当我使用storyboard id时如何将数据传递到目标视图?

时间:2016-01-05 08:15:39

标签: ios objective-c uistoryboard uistoryboardsegue

基本上,当我想将数据从源视图传递到目标视图时,我使用" prepareForSegue"方法并使destinationView等于segue的destinationView。

但是如果我想在下面的代码中使用Storyboard ID来呈现我当前视图的上方:

MyCustomViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
[self presentViewController:vc animated:YES completion:nil];

如何使用Storyboard ID ??

将数据从当前视图传递到目标视图

3 个答案:

答案 0 :(得分:4)

同样的方式..

MyCustomViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
vc.someProperty = something;  //use your data here
[self presentViewController:vc animated:YES completion:nil];

答案 1 :(得分:0)

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString:@"SEGUE_NAME_HERE"])
    {
        // Get reference to the destination view controller
        ViewController *objVc = [segue destinationViewController];
        objVc.objectProperty = object;

    }
}

答案 2 :(得分:0)

我经常快速完成,这不是最佳做法,但我使用NSUserDefaults远程保存数据,而不创建CoustomViewController。