我在所謂的應用程序中有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