在工作区中的第二个项目中从故事板实例化视图控制器

时间:2016-07-31 07:44:29

标签: ios swift xcode storyboard xcode-workspace

我创建了一个包含2个项目的工作区,让我们分别用包标识符com.domain.acom.domain.b称它们为A和B.每个项目都有一个名为Main.storyboard的故事板。我在项目A的故事板中有一个按钮,我想从项目B中的故事板中实例化一个视图控制器,其代码如下:

@IBAction func clicked(sender: AnyObject) {
    let bundle = NSBundle(identifier: "com.domain.b")
    let storyBoard = UIStoryboard(name: "Main", bundle: bundle)
    let vc = storyBoard.instantiateViewControllerWithIdentifier("aVC")
    self.presentViewController(vc, animated: true, completion: {})
}

我还在项目B中设置了视图控制器的故事板ID:

Storyboard ID

但是当我构建并运行项目时,我得到了这个例外:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x7f8578cd34d0>) doesn't contain a view controller with identifier 'aVC''

注意:

我使用断点并在bundle的代码中找到变量nil为什么?!

0 个答案:

没有答案
相关问题