ios - 如何在 performSegueWithIdentifier 中使用 sender?

标签 ios

我已经使用以下方法以编程方式启动了 segue:

[self performSegueWithIdentifier:@"loginToCategories" sender:object];

我想知道新的 View Controller 对象是否可以访问我在发件人中插入的“对象”。

最佳答案

如果您希望目标 View Controller 获得 segue 的发送者,您需要从 prepareForSegue 方法向 destinationViewController 发送消息。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"MySegue"]) {
        MyViewController *destinationViewController = (MyViewController *)segue.destinationViewController;
        destinationViewController.sender = sender;
    }
}

This question高度相似。

关于ios - 如何在 performSegueWithIdentifier 中使用 sender?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25965873/

相关文章:

ios - 显示 UIAlertController 的简单 App Delegate 方法(在 Swift 中)

iphone - iOS idleTimerDisabled 行为

ios - 如何更新静态库架构以支持 arm64 Build?

ios - 从另一个包含字符串的数组快速返回数组

ios - 知道耳机何时连接到 3.5 毫米插孔仅在应用程序启动前未连接时有效

ios - 在不使用 NavigationController 的情况下将导航栏添加到 UITableViewController

ios - 从 YouTube JSON 数据 Objective C 获取缩略图

ios - 以编程方式创建和显示 UIBarButtonItem 的正确方法是什么?

没有 iPhone 6 Plus 的 iOS 应用程序预览

ios - 尝试在 Amazon Cognito 中同步数据集会返回 CognitoSyncError