按顺序将数据从一个ViewController传递到另一个ViewController

时间:2014-08-11 16:46:30

标签: ios objective-c storyboard segue

以下代码有什么问题。它与SIGABRT崩溃(无法识别的选择器发送到实例)

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"%@",valueName);
    if([segue.identifier isEqualToString:@"pushView"])
    {
    secondViewController *svc = (secondViewController *)[segue destinationViewController];

    svc.passedName = valueName;
    }

}

valueName iVar是我要传递的NSString。

1 个答案:

答案 0 :(得分:0)

1)请勿忘记FirstViewController NavigationController

2)不要忘记设置您的segue标识符。

enter image description here

3)使用相同的代码:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    //for example if you value is "123"
    NSString *valueName = @"123";
    NSLog(@"%@",valueName);
    if([segue.identifier isEqualToString:@"pushView"])
    {
        secondViewController *svc = (secondViewController *)[segue destinationViewController];
        svc.passedName = valueName;
    }
}

4)现在,在secondViewController中,在[{1}}中记录您的值,看看它是否已通过......

ViewDidLoad

5)您应该得到的结果:

enter image description here