场景无法访问...没有标识符

时间:2016-02-06 03:38:41

标签: ios xcode swift viewcontroller

我收到了这个警告:

  

由于缺少入口点而没有场景,因此无法访问场景   运行时访问的标识符 - instaniateViewControllerWithIdentifier

虽然Xcode对于没有入口点是正确的,但它确实有以下定义:

Custom Class : Class = ViewControllerCatalog
Identify : Storyboard ID = vccatalog

我还需要定义什么来避免此错误?

1 个答案:

答案 0 :(得分:4)

有两种方法可以转换到故事板中的场景:您既可以转到它,也可以使用其故事板标识符对其进行实例化。但是警告指出你既没有任何segues也没有storyboard标识符,因此没有办法实例化那个场景。您可以实例化基类,但除非使用instantiateViewControllerWithIdentifier,否则无法使用故事板场景(及其所有控件以及所有IBOutletIBAction引用)。并且为了使用该故事板方法,场景显然需要故事板标识符。

所以,如果你不打算使用segues,那必然意味着你将以编程方式转换到这个场景。因此,首先请确保指定故事板标识符:

enter image description here

然后实例化链接到该场景的DetailsViewController,如下所示:

let controller = storyboard!.instantiateViewControllerWithIdentifier("DetailsScene")   // or, if you need to access custom properties, `storyboard!.instantiateViewControllerWithIdentifier("DetailsScene") as! DetailsViewController`

// now use it as you see fit, e.g.,
//
// showViewController(controller, sender: self)