一周后我打开了我的项目,似乎对于我在 StoryBoard
中创建的所有新 UIViewController
,instantiateViewControllerWithIdentifier
返回的是零。项目中已有的所有 ViewControllers
都工作正常。
GCHConnectViewController* gchCVC = [self.storyboard instantiateViewControllerWithIdentifier:@"GchConnect"];
navigationController.viewControllers = @[gchCVC];
第一行返回 nil,我最初的想法是 self.storyboard
返回 nil,所以我尝试了这个并设置了断点。
if (self.storyboard != nil) {
GCHConnectViewController* gchCVC = [self.storyboard instantiateViewControllerWithIdentifier:@"GchConnect"];
navigationController.viewControllers = @[gchCVC];
}
它会进入 if 并在第二行崩溃..
我还正确添加了类和 storyboard
id。
如果我尝试加载另一个已经存在的 ViewController
,它可以工作,但不能加载新的。
似乎无法弄清楚问题是什么。感谢您的帮助。
我有一个抽屉导航。切换到其他 ViewController,除了带有标识符 'GchConnect' 的那个(即 indexPath.section == 1 和 indexpath.row == 0 )是有效的。它们都在同一个 Storyboard中
最佳答案
如果你有多个 Storyboard,self.storyboard
返回当前 UIViewController
所在的 Storyboard。你需要检查 Storyboard的名称是否为“GchConnect”。并用 storyboardWithName:bundle: 实例化该 Storyboard
UIStoryboard storyboard = [UIStoryboard storyboardWithName:bundle:nil];
GCHConnectViewController* gchCVC = [storyboard instantiateViewControllerWithIdentifier:@"GchConnect"];
关于ios - Objective-C instantiateViewControllerWithIdentifier 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37545467/