0

这种方法对我不起作用。我正在工作几分钟。我莫名其妙地做不到。

这是我的代码。

- (IBAction)donebutton:(id)sender {
    AddTaskViewController *addtask = [[AddTaskViewController alloc]initWithNibName:@"AddTask" bundle:nil];
    addtask.testlabel.text = self.zaman1.text;
    [self dismissViewControllerAnimated:YES completion:nil];

}

一切正常,但无法正常工作。不是这样吗?这是错误的?

4

3 回答 3

1

您必须在您的方法中分配此字符串,在初始化视图之前无法配置viewWillAppearIBOutlets(我假设是 IBOutlet UILabel *)。testlabel如果这没有帮助,请说明错误是什么。

于 2013-04-23T23:46:00.397 回答
0

更好的方法是NSString*AddTaskViewController. 你可以这样做:

添加AddTaskViewController.h以下内容:

@property (nonatomic, strong) NSString* myLabelsText;

然后AddTaskViewController.m确保将其添加到viewWillAppear

self.testlabel.text = self.myLabelsText;

现在假设您已经适当地声明了您的testLabelmyLabelsText它们被合成,您的视图控制器将在适当的时间正确应用字符串,然后您的函数应该更改为:

- (IBAction)donebutton:(id)sender {
    AddTaskViewController *addtask = [[AddTaskViewController alloc]initWithNibName:@"AddTask" bundle:nil];

    // Set the value on your new NSString* property and let the view controller handle the rest
    addTask.myLabelsText = self.zaman1.text;

    // Don't you want to 'present' the view controller rather than 'dismiss' after having provided it with data?
    [self dismissViewControllerAnimated:YES completion:nil];

}
于 2013-04-24T00:50:40.480 回答
0

You should use delegate protocols and instead of setting properties of button on previous view controller just pass a string back. This question should help you in implementing Delegate protocol

dismissModalViewController AND pass data back

于 2013-04-24T01:22:13.727 回答