iOS 如何使用 segue 获取对嵌入 Storyboard容器中的 View Controller 的引用?

标签 ios objective-c uiviewcontroller embed uistoryboard

我有一个 Storyboard和一个带有容器 View 的 View Controller 。在 Storyboard中,我使用“嵌入”segue 定义了从容器到另一个 View Controller 的连接。 如何从父 View Controller 中获取对嵌入式 View Controller 的引用?

我已经创建了对容器的引用,但发现它只是一个 UIView

这是我正在使用的转场 enter image description here

enter image description here

最佳答案

您必须在主 ViewController 中实现 prepareForSegue 并在 StoryBoard 中指定一个标识符。

- (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];

    }
}

关于iOS 如何使用 segue 获取对嵌入 Storyboard容器中的 View Controller 的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25436433/

相关文章:

ios - 获取 AVAudioPlayer 一次播放多种声音

ios - UITableView的reloadRowsAtIndexPaths : seems to break insertRowsAtIndexPaths:

iphone - 为什么 viewDidLoad 中的 self.navigationController 为 null?

objective-c - 将 CAMediaTimingFunction 与基于 block 的 UIView 动画一起使用

ios - UINaviagtionBar subview 在 UIViewController "Back"转换期间不会淡出

swift - 从 GameScene.swift 切换到 View Controller

ios - Gstreamer 1.2.3 (iOS) 上的 Videosink

ios - iOS 蓝牙 LE 加密是强制性的吗?

ios - 无法将 NSUserDefaults 与 Apple Watch 同步

ios - 使用 SWRevealViewController 登录 View