这个方法对我不起作用。我在工作几分钟。不知何故,我做不到。
这是我的代码。
- (IBAction)donebutton:(id)sender {
AddTaskViewController *addtask = [[AddTaskViewController alloc]initWithNibName:@"AddTask" bundle:nil];
addtask.testlabel.text = self.zaman1.text;
[self dismissViewControllerAnimated:YES completion:nil];
}一切正常,但不能正常工作。难道不是这样吗?这是错的吗?
发布于 2013-04-24 07:46:00
您必须在viewWillAppear方法中指定此字符串,在初始化视图之前,不能配置IBOutlets (我假设testlabel是一个IBOutlet UILabel *)。如果这不起作用,请详细说明错误是什么。
发布于 2013-04-24 08:50:40
更好的方法是在AddTaskViewController上创建一个NSString*属性。你可以这样做:
在AddTaskViewController.h中添加以下内容:
@property (nonatomic, strong) NSString* myLabelsText;然后在AddTaskViewController.m中,一定要在viewWillAppear中添加以下内容
self.testlabel.text = self.myLabelsText;现在假设你已经适当地声明了你的testLabel和myLabelsText,并且它们被合成了,你的视图控制器将在适当的时间正确地应用字符串,然后你的函数应该被修改为:
- (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-24 09:22:14
你应该使用委托协议,而不是在以前的视图控制器上设置按钮的属性,只需传递回一个字符串。这个问题应该会帮助你实现委派协议
https://stackoverflow.com/questions/16180918
复制相似问题