无法在代码中调用segue(Swift) [英] Cant call a segue in code (Swift)
问题描述
我在导航控制器中嵌入了一些视图。
I have a few views embedded in a navigation controller.
我创建了一些segues(一些从按钮到其他视图控制器,一些来自一个视图控制器)另一个。
I've created a few segues (some from buttons to other view controllers, some from one view controller to another one.
例如我从一个按钮到名为name2的视图控制器有一个segue(显示),当我按下按钮时效果很好,但是当我尝试以编程方式调用应用程序崩溃并给出错误。
for example I have a segue (Show) from one button to a view controller called name2, when I press the button it works great, but when I try to call it programmatically the app crashes and gives an error.
这就是我在 ViewController1
self.performSegueWithIdentifier("name2", sender: self)
这是从 ViewController1 到 ViewController2
我也有一个segue不是连接按钮而是从vc1连接到vc2,给出了同样的错误。
I also have a segue that is connected not to a button but from vc1 to vc2, gives the same error.
这是我得到的奇怪错误:
This is the strange error I get:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (ViewController2) has no segue with identifier 'name2''
我尝试清理产品并重置模拟器。
I tried cleaning the product and also reseting the simulator.
我的故事板的屏幕截图
viewcontroller1的身份检查器的屏幕(在我的项目中实际上称为ViewController)
A screen of the identity inspector of viewcontroller1 (it is actually called ViewController in my project)
segue的屏幕截图(name3)
A screen shot of the segue (name3)
segue的选项:
The options of the segue :
编辑:
我发现当我将按钮作为IBAction连接然后调用 performSegueWithIdentifier(LogIn,发件人:自己)
从按钮开始正常工作。
I found that when I connect a button as an IBAction and then call performSegueWithIdentifier("LogIn", sender: self)
from the button it works correctly.
任何帮助?
推荐答案
好的答案是我很笨,
每当我创建新的ViewControllers时,我都是子类 ViewController
这是我的第一个ViewController,而不是 UIViewController
,这使得它以递归方式运行。
Ok the answer is that I'm pretty dumb,
Whenever I was creating new ViewControllers, I was subclassing ViewController
which was my first ViewController, instead of UIViewController
which made it run recursivly.
这篇关于无法在代码中调用segue(Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!