2017-06-20 79 views
0

我试图推动新的视图控制器,但死机的第一行与此错误消息为什么在实例化视图控制器时应用程序崩溃?

EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

我有双三重检查类的名称和故事板ID和他们是正确的。不知道问题是什么。

func showUsers() { 
    let vc = self.storyboard?.instantiateViewController(withIdentifier: "group") as! GroupViewController 
    self.navigationController?.pushViewController(vc, animated: true) 
} 
+0

任何消息? – Larme

+0

@Larme在控制台没有消息。您的故事板中的 – joethemow

+0

Groupviewcontroller是否按组识别? –

回答

3

你能检查你的vc是不是零?

您有可选的storyboard和强制as,在推vc之前,有几件事可能会出错。它可以是nil,也可以不是GroupViewController实例。

你可以通过尝试这样的东西开始:

if let vc = self.storyboard?.instantiateViewController(withIdentifier: "group") as? GroupViewController { 
    self.navigationController?.pushViewController(vc, animated: true) 
} 

,看你是否真正得到非空vc

编辑:根据你的评论 - 看起来你确实得到nil在某些时候。然后你需要检查确切的地方。你的self.storyboard是不是零?

你可以实例化你的视图控制器吗? method docs

If the specified identifier does not exist (or is nil) in the storyboard file, this method raises an exception.

我建议打破你实例为单独的步骤,并检查他们每个人这样的调试:在控制台

if let storyboard = self.storyboard { 
    let vc = storyboard.instantiateViewController(withIdentifier: "group") 
    if let groupVC = vc as? GroupViewController { 
     self.navigationController?.pushViewController(groupVC, animated: true) 
    } 
} 
+0

是的,如果故事板= self.storyboard',它就会失败。现在正常工作:) – joethemow

0

请检查下面给定的点: -

1)请检查用于GroupViewController驻留在相同的故事板或不

2)调试代码,并检查对于VC对象它不应该是零。

3)请检查群组 GroupViewController的标识符,特别是故事板。

相关问题