【发布时间】:2014-02-02 22:53:06
【问题描述】:
- 创建一个新的单视图项目(例如,“测试”)
- 在主情节提要中,创建两个标题为
One和Two的视图控制器 - 使One成为初始视图控制器 - 将标签
One放在视图控制器One的内容中,将标签Two放在Two中 -
在
TestViewController.m的viewDidLoad中包含以下内容:// instantiate the new view controller UIStoryboard *storyboard = self.storyboard; TestViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Two"]; // Change the view viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentViewController:viewController animated:YES completion:nil]; 保存、构建并运行。
我一直收到Storyboard does not contain view controller 'Two' 种类的错误。使用断点,我发现问题出在实例化步骤。然而,上面的代码直接取自 Apple 的 View Controller Programming Guide。
我浏览了这个站点,发现很多人在以编程方式实例化视图控制器时遇到问题。有什么明确的解决办法吗?
【问题讨论】:
-
当您说标题时,您的意思是 Storyboard ID,因为这是由 instantiateViewControllerWithIdentifier: 使用的?
标签: ios uiviewcontroller uistoryboard