我尝试像这样从 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/