ios - 您是否在同一个 prepareForSegue 方法中为一个 View Controller 的所有 segues 实现了行为?

标签 ios iphone objective-c

我要了解 prepareForSegue 如何在单个 View Controller 中针对不同类型的 segues 工作...我的意思是, View Controller 可能在单个 View 中具有不同类型的 segues 并为每个执行不同的任务它们都在 prepareForSegue 方法中,所以它们都在同一个方法中吗?

我知道您定义的每个 segue 都会将一个 segue 对象发送到 prepareForSegue 方法,但是该方法如何知道要执行哪个代码?

谢谢,

最佳答案

是的,您将在该单个函数中为该 View Controller 执行所有的 segue 逻辑。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"Prepare for segue: %@", [segue identifier]);
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([[segue identifier] isEqualToString:@"segue1"]) {
        // logic for segue 1
    } else if ([[segue identifier] isEqualToString:@"segue2"]) {
        // logic for segue 2
    } else if ([[segue identifier] isEqualToString:@"segue3"]) {
        // logic for segue 3
    }
}

关于ios - 您是否在同一个 prepareForSegue 方法中为一个 View Controller 的所有 segues 实现了行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22849753/

相关文章:

objective-c - 从我的iOS 5应用打开Twitter应用

xcode - 问题 iOS SDK 4.0

ios - 强制用户从应用商店ios下载最新版本

iOS 8.3 : UIActivityViewController shows extraneous row

ios - 如何区分 UICollectionViewLayout 准备布局的原因(iOS 6)?

iphone - iPhone上的GL渲染线程值得吗?

ios - 如何向 UITableViewCell 添加自定义分隔符?

ios - NSUserDefaults 不保存整数

objective-c - Mac 应用程序中的数据库选项

objective-c - 子类是否继承了 Objective-C 中其父类的协议(protocol)?