简体   繁体   English

Swift:应用程序在segue期间崩溃

[英]Swift: App crashing during segue

I have 3 view controllers that I'm navigating between. 我有3个在其中浏览的视图控制器。 When I open my app, I start at Controller1, which I can then use to navigate to Controller2 or Controller3. 打开应用程序时,我从Controller1开始,然后可以使用它导航到Controller2或Controller3。 I can navigate to each of them fine individually, however, after I go to Controller3, return to Controller1, then try to navigate to Controller2, I get an EXC_BAD_ACCESS with code = 1. There is no exception or error message given at all, it just takes me to my AppDelegate file and gives me that error code. 我可以分别导航到它们的每一个,但是,当我转到Controller3之后,返回到Controller1,然后尝试导航到Controller2,我得到了代码= 1的EXC_BAD_ACCESS。根本没有异常或错误消息给出,它只是将我带到我的AppDelegate文件,并给了我该错误代码。

I don't know what the issue is, but something that seems relevant is that I'm setting Controller3 as the navigation controller's delegate. 我不知道问题是什么,但似乎相关的是我将Controller3设置为导航控制器的委托。 I have a fourth navigation controller that also is set as a delegate as well, and causes the same behavior when I from 1->4->1->2, just like with 1->3->1->2. 我还有第四个导航控制器,它也同样设置为委托,并且当我从1-> 4-> 1-> 2进行操作时会导致相同的行为,就像1-> 3-> 1-> 2一样。 I have no issue going from 1->4->1->3 or 1->3->1->4, only when 2 is involved. 我没有问题从1-> 4-> 1-> 3或1-> 3-> 1-> 4,只有当涉及到2时。 I'm not sure if the issue is the delegates, and the fact that 2 isn't being set as one. 我不确定问题是否出在代理人上,也不确定2是否未设置为1。 Once again, I can navigate to it fine by itself, but not after navigating to one of the other 2 sub-view controllers. 再一次,我可以自行导航到它,但不能导航到其他2个子视图控制器之一。

如果将Controller3或Controller4设置为导航控制器委托,则需要在这些类的viewWillDisappear函数中将其清除,否则最终将得到无效的引用,这就是导致崩溃的原因

I ran into this same kind of crash, so I will share what the issue was for me: 我也遇到过类似的崩溃,因此我将分享我的问题所在:

  1. I had created a subclass of UIWebView. 我创建了UIWebView的子类。
  2. In my storyboard, I dragged a UIWebView onto the canvas and changed it's class to be my subclass. 在我的情节提要中,我将UIWebView拖动到画布上,并将其类更改为我的子类。

That was all working. 一切正常。 The app had already passed through our QA team, was "accepted" by the business owner, and we were ready to push it to the app store. 该应用程序已经通过了我们的质量检查小组,被企业主“接受”,我们已经准备好将其推入应用程序商店。

Then I was told, "You can't use UIWebView. You must use WKWebView." 然后我被告知:“您不能使用UIWebView。必须使用WKWebView。”

Fine, I changed my subclass to inherit from WKWebView, tweaked my internal class logic, and....splat. 很好,我将子类更改为从WKWebView继承,调整了内部类逻辑,然后..splat。 Trying to segue to that view controller would crash just as noted by the OP. 正如OP所指出的那样,尝试隔离到该视图控制器将崩溃。

The problem was my storyboard: Because it was trying to instantiate my subclass, it was basically attempting to create a WKWebView which is NOT necessarily supported in Interface Builder (my friend says it might be ok in later versions, but I didn't verify). 问题是我的情节提要:因为它试图实例化我的子类,所以它基本上是在尝试创建WKWebView,而该接口不一定在Interface Builder中得到支持(我的朋友说,在更高版本中可能没有问题,但我没有验证) 。

TL;DR TL; DR

The moral of the story is that if you have a subclassed object on your story board whose ancestor can't be dragged from the toolbox, then you will probably crash when you segue. 这个故事的寓意是,如果故事板上有一个子类对象,而其祖先无法从工具箱中拖动,那么您在进行搜索时可能会崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM