如何将值从firstviewcontroller传递到xcode中的第三视图控制器?

时间:2014-10-07 10:28:11

标签: objective-c xcode

我在firstviewcontroller str1中声明了一个字符串,我希望在第三视图控制器中获取该字符串并在if循环中使用它。

firstviewcontroller

 SecondViewController *secondview=[[SecondViewController alloc]init];
secondview.str1=[name objectAtIndex:indexPath.row];
[self.navigationController pushViewController:secondview animated:YES];

thirdviewcontroller

if([str1 isEqualToString:@"X"])
   //&&[str12 isEqualToString:@"hospital"])

但似乎没有工作.pls有助于理清

2 个答案:

答案 0 :(得分:0)

试试这样:

SecondViewController *secondview=[[SecondViewController alloc]]nitWithNibName:@"SecondViewController" bundle:nil];
secondView.str1 = @"testString";
[self.navigationController pushViewController:secondView animated:YES];

答案 1 :(得分:0)

prepareForSegue方法中,您可以在每个视图控制器上设置@property。您需要使用故事板ID或将视图控制器设置为强大的@properties。

VC1:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if (_secondView && _secondView.yourPropertyName)
        _secondView.yourPropertyName = @"something";
}

VC2:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if (_thirdView && _thirdView.yourPropertyName)
        _thirdView.yourPropertyName = self.yourPropertyName;
}