简体   繁体   English

Xcode应用程序在Iphone上运行但在Ipad上崩溃

[英]Xcode application running on Iphone but crashing on Ipad

I made a universal application that contains NIB files for both ipad and iphone UI's. 我制作了一个通用应用程序,其中包含ipad和iphone UI的NIB文件。 In my view controllers initWithNibName method I call UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM() to detect whether the controller is running on iphone or ipad. 在我的视图中,控制器initWithNibName方法我调用UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()来检测控制器是在iphone还是ipad上运行。

I then launch their respective nib files. 然后我启动他们各自的nib文件。 When I run the app on iphone, it works fine, but when I run it on ipad it eventually crashes with a EXC_BAD_ACCESS error. 当我在iphone上运行应用程序时,它运行正常,但是当我在ipad上运行它时,它最终会因EXC_BAD_ACCESS错误而崩溃。 This error occurs when I use a view controller to launch another view controller, which then launches another one in the navigation stack. 当我使用视图控制器启动另一个视图控制器,然后在导航堆栈中启动另一个视图控制器时,会发生此错误。 This error occurs as soon as I click the view that belongs to the third controller of the stack. 单击属于堆栈的第三个控制器的视图时,会发生此错误。

I cannot distinguish a difference between the NIB files that would cause a crash. 我无法区分导致崩溃的NIB文件之间的区别。 I have been working tirelessly to figure out why this is happening but I cannot fix this error. 我一直在不知疲倦地弄清楚为什么会这样,但我无法解决这个错误。 Does anyone have any insight into what might be going on? 有没有人对可能发生的事情有任何见解?

Any advice on how to approach fixing this problem would be very appreciated. 任何关于如何解决这个问题的建议都将非常感激。

The first thing you should do is enable the "All Exceptions" break point. 你要做的第一件事就是启用“All Exceptions”断点。 This will often accurately tell you the line of code where the EXC_BAD_ACCESS is happening. 这通常会准确地告诉您发生EXC_BAD_ACCESS的代码行。

在此输入图像描述

Next, I would turn on zombies and see where the over-release is happening. 接下来,我会打开僵尸,看看过度释放的位置。 To do so, in Xcode, while holding the option key, click Product | 为此,在Xcode中,在按住选项键的同时,单击Product | Run.... In the ensuing window, add NSZombieEnabled to the environment variables list. 运行....在随后的窗口中,将NSZombieEnabled添加到环境变量列表中。

在此输入图像描述

Then run. 然后跑。 Do the normal things you do to cause the crash and see where the debugger lands. 执行正常操作以导致崩溃并查看调试器所在的位置。 With any luck, it will stop where the problem is actually occurring. 运气好的话,它会停在问题实际发生的地方。

When you get a EXC_BAD_ACCESS it means you're trying to access/release something that's already been released. 当您获得EXC_BAD_ACCESS时,它意味着您正在尝试访问/释放已经发布的内容。 If you're in a non-ARC situation, it normally means you've inadvertently released something when you didn't mean to, so just check for alloc/init and release balance. 如果你处于非ARC状态,通常意味着你无意中发布了一些你不想要的东西,所以只需检查alloc / init和release balance。 If, however, you're in an ARC situation, I would bet it has to do with not niling a delegate when a view controller gets released. 但是,如果你处于ARC状态,我敢打赌,当视图控制器被释放时,它不会引发委托。

For example, if you have a MKMapView and have set its delegate to your view controller, you should nil its delegate when your view gets unloaded or dealloc'd. 例如,如果您有一个MKMapView并且已将其委托设置为您的视图控制器,则应在视图被卸载或取消分配时将其委托为零。 Otherwise, messages will continue to get set to it. 否则,消息将继续设置为它。 Or, another possibility is that you've added your view controller as an NSNotificationCenter observer and didn't remove it as an observer when the view controller was unloaded or dealloc'd. 或者,另一种可能性是您已将视图控制器添加为NSNotificationCenter观察器,并且在卸载或取消分配视图控制器时未将其作为观察者删除。

Another possibility is that you're re-using view controllers between the two versions of your universal app. 另一种可能性是您在通用应用程序的两个版本之间重新使用视图控制器。 If you are accessing anything by an identifier that doesn't exist in the nib for the iPad, that would cause a crash--though if you're using nibs as opposed to storyboards, that may not be an issue. 如果您通过iPad的笔尖中不存在的标识符访问任何内容,那将导致崩溃 - 尽管如果您使用的是笔尖而不是故事板,那么这可能不是问题。

That's about all I can think of for now. 这就是我现在能想到的一切。 Try to zero in on where it's happening and post code here if you still can't figure it out. 尝试将其发生的位置归零并在此处发布代码,如果您仍然无法弄明白的话。

Best regards. 最好的祝福。

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

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