0

当我查看 UIBarButtonItem 并从 Connections Inspector 拖动“推送”segue 时,我可以将它连接到情节提要中的另一个视图控制器。当我运行它并单击 UIBarButtonItem 时,我在 IB 中连接的 ViewController 神奇地出现了。

我的问题是:这发生在哪里?这个,“推”事件。父 ViewController 中有方法吗?像:“PushSegue”?我想将信息从导航视图控制器传递给连接的 ViewController。例如,如果我想在那一刻弹出一个 UIAlertView,我会在哪里做呢?在 ViewController 类的某个地方?

4

1 回答 1

2

一旦调用了一个segue(通过按下按钮),它就会调用prepareForSegue。在 prepareForSegue 中,您检查调用了哪个 segue,然后可以运行您想要准备下一个视图控制器的任何代码。

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

    // Pass any objects to the view controller here, like...
    [vc setMyObjectHere:object];
}
}
于 2011-12-09T22:28:07.040 回答