我有两个名为DataPass和ViewController的视图控制器。我想将数据从DataPass传递给ViewController。我在ViewController中有一个标签,我的ViewController中有一个UIButton,它会解散自己,而解雇会将数据传递给DataPass中的标签。
我做不到。请帮忙。这是我的代码:
ViewController.h
@interface ViewController : UIViewController
- (IBAction)sayfaGec:(id)sender;
@property (retain, nonatomic) IBOutlet UILabel *label;
+(ViewController *)hop;
ViewController.m
+(ViewController *)hop{
static ViewController *myInstance = nil;
if (myInstance == nil){
myInstance = [[[self class]alloc]init];
myInstance.label.text = @"test";
}
return myInstance;
}
DataPass.h
- (IBAction)sayfaKapat:(id)sender;
DataPass.m
- (IBAction)sayfaKapat:(id)sender {
[ViewController hop].label.text = @"ddsg";
[self dismissModalViewControllerAnimated:YES];
}
答案 0 :(得分:0)
ViewController.h
- (void)setLabelData:(NSString:)aString;
ViewController.m
- (void)setLabelData:(NSString:)aString{
[yourLabel setText:aString];
}
在您的DataPass中,您说:
ViewController *vContr = [[ViewController aloc]init];
[vContr setLabelData: @"asta la vista baby!"];
[self.view addSubview:vContr.view];