2013-12-11 117 views
0

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

    } 

} 
+0

你在主線程上調用setText方法嗎? –

+0

看起來你正在做的一切都是正確的。添加一些'NSLog'來查看你到達'prepareForSegue:',並且你輸入'if'。 – dasblinkenlight

+0

我做了,看起來像它進入如果但我仍然得到相同的結果標籤。 – user1433743

回答

0

你的二傳手,你需要到:

_text = paramText; 
0

我不知道我是否理解correctly.But如果您例如,將VC1文本字段值轉換爲字符串

if([segue.identifier isEqualToString:@"ikinciEkran"]) { 
NSString *textLocalString = [NSString stringWithFormat:@"%@",Viewcontroller1.text]; 
} 
ViewController2 *nextController = segue.destinationViewController; 
     nextController.introString = textLocalString; 

然後,聲明Introstring在Viewcontroller2

@property(weak,nonatomic) NSString *introString; 

在ViewController2.m,把的NSLog和檢查

NSLOG(@"TransferString:%@",Introstring); 

如果vewcontrller之間傳輸nstring值,這將作品。

+0

它傳遞的文字很好,但是self.myLabel.text = paramText;在setText方法中。 – user1433743