1

我有两个视图控制器,称为 DataPass 和 ViewController。我想将数据从 DataPass 传递到 ViewController。我在 ViewController 中有一个标签,在我的 ViewController 中有一个 UIButton,它将自行关闭,并且在关闭时会将数据传递给 DataPass 中的标签。

我做不到。请帮忙。这是我的代码:

视图控制器.h

@interface ViewController : UIViewController
- (IBAction)sayfaGec:(id)sender;
@property (retain, nonatomic) IBOutlet UILabel *label;
+(ViewController *)hop;

视图控制器.m

+(ViewController *)hop{
    static ViewController *myInstance = nil;
    if (myInstance == nil){
        myInstance = [[[self class]alloc]init];
        myInstance.label.text = @"test";
    }
    return myInstance;
}

数据通行证

- (IBAction)sayfaKapat:(id)sender;

数据通行证

- (IBAction)sayfaKapat:(id)sender {
    [ViewController hop].label.text = @"ddsg";
    [self dismissModalViewControllerAnimated:YES];
}
4

1 回答 1

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];
于 2012-07-28T18:55:03.683 回答