我正在遵循这里使用多个故事板的方法: http://www.newventuresoftware.com/blog/organizing-xcode-projects-using-multiple-storyboards/
但我想在用户按下按钮后切换故事板, 我得到的错误是:
警告:尝试显示SWRevealViewController MainViewController视图不在窗口层次结构中!
切换故事板的代码是:
var storyboard = UIStoryboard(name: "Search", bundle: nil)
var controller = storyboard.instantiateViewControllerWithIdentifier("theRealID") as! UIViewController
self.presentViewController(controller, animated: true, completion: nil)
仅供参考,如果我这样做,我可以加载第二个故事板,但是....这不是我想要的时候。按下按钮后我想要它。
override func viewDidAppear(animated: Bool) {
//super.viewDidAppear(animated)
var storyboard = UIStoryboard(name: "Search", bundle: nil)
var controller = storyboard.instantiateViewControllerWithIdentifier("theRealID") as! UIViewController
self.presentViewController(controller, animated: true, completion: nil)
}
答案 0 :(得分:0)
您只需要为按钮创建一个IBAction并实例化一个新的视图控制器,如下所示:
presentViewController( UIStoryboard(name: "Search", bundle: nil).instantiateViewControllerWithIdentifier("theRealID") as! UIViewController, animated: true, completion: nil)
如果您需要,也可以将其与导航控制器一起使用:
presentViewController( UIStoryboard(name: "Search", bundle: nil).instantiateViewControllerWithIdentifier("theRealID") as! UINavigationController, animated: true, completion: nil)