我在所谓的应用程序中有2个屏幕。第一个(ViewController.m)获取该值并将其发送到ViewController2.m中的方法。然后,第二个视图中标签的预加载文本将更改为传输的字符串。发送字符串到destinationViewController
情况是:
1)的NSLog打印从第一页的文本框
2)采取然而,的setText方法不改变标签的文本正确的输出。
3)奇怪的是,相同的代码工作,以改变viewDidLoad中的标签的文本。
- (void) setText:(NSString *)paramText {
self.myLabel.text = paramText;
NSLog(@"%@", paramText);
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.myLabel.text = @"try";
}
我如何调用从ViewController.m中的setText:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ikinciEkran"]) {
ViewController2 *nextController = segue.destinationViewController;
[nextController setText:self.myText.text];
}
}
你在主线程上调用setText方法吗? –
看起来你正在做的一切都是正确的。添加一些'NSLog'来查看你到达'prepareForSegue:',并且你输入'if'。 – dasblinkenlight
我做了,看起来像它进入如果但我仍然得到相同的结果标签。 – user1433743