2013-12-11 115 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