我读到:
为了创建页面内容 View Controller ,我们添加了一个辅助方法。 在这个方法中,在某一点,有这一行:
if let pageContentViewController = storyboard?.instantiateViewControllerWithIdentifier("PageContentViewController") as? PageContentViewController { ....` } `
我的问题是:
为什么之前没有声明“storyboard”,但现在出现在上面一行?
最佳答案
有时为了使项目更容易,项目是跨各种 Storyboard构建的。
如果你只有一个 Storyboard,你知道要在这个只有一个 Storyboard上访问其他 View Controller ,你会说:
self?.instantiateViewController....
// Here self refers to itself.. the only storyboard you havve
但是,在您的代码中,正在尝试跨不同的 Storyboard访问 View Controller 。这个不同的 Storyboard会有一个 id(你在事件检查器中设置)
//This is how you access a view controller in a different storyboard
let storyboard = UIStoryboard(name: "yourStoryBoardID", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("yourViewControllerID") as UIViewController
self.presentViewController(controller, animated: true, completion: nil)
此链接:“http://www.newventuresoftware.com/blog/organizing-xcode-projects-using-multiple-storyboards”对于提供对多个 Storyboard的引用非常有帮助。
明确一点:这与页面 View Controller 无关,这是因为我们使用的是多个 Storyboard。 另外,如果您能提供更多代码或引用资料就更好了。
关于swift - UIPageViewController阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37461152/