ios - 如何通过标识符在 Storyboard 中获取 View Controller ?

标签 ios objective-c iphone

我尝试像这样从 Storyboard中获取 View Controller :

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"vc"];
    ViewController *avc = ((UINavigationController *)(_window.rootViewController)).topViewController;

但它们不是同一个对象:

(lldb) po vc <ViewController: 0x17eaee50>
(lldb) po avc <ViewController: 0x17e72970>

为什么?

最佳答案

它们属于同一类,但实例不同。 instantiateViewControllerWithIdentifier 实例化一个新的 View Controller ,顾名思义:)。

关于ios - 如何通过标识符在 Storyboard 中获取 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29419811/

相关文章:

ios - 为什么指针无法取回新值? iOS

ios - 是否可以在 2 个 iOS 应用程序之间创建链接?

ios - 生成钥匙串(keychain) IBM Mobile First V 7.1

objective-c - 更好的 PMTabBarControl/Cocoa 选项卡

iphone - 如何将图像添加到 UIToolBar?

iphone - iPhone 上的加速器范围是多少?

iphone - 我如何向分组的 UITableView 添加阴影(如官方 Twitter 应用程序所示)?

ios - 在设备上运行应用程序时 EXC_BAD_ACCESS

ios - 向 UITableView 添加新项目而不替换旧项目

objective-c - 将 UIView 转换为 CALayer