简体   繁体   English

在Xcode 5.1.1中发现的问题,而不是在Xcode 6中发现的问题

[英]Issue found in Xcode 5.1.1 and not in Xcode 6

I have a problem if i build my application from Xcode 5 and run the same on a device with iOS 8 i see a crash with a error message 如果我从Xcode 5构建应用程序并在装有iOS 8的设备上运行该应用程序,我会遇到问题,并显示崩溃并显示错误消息

[myViewController numberOfSectionsInTableView:] message sent to deallocated instance 0x1846c960

I have allocated the class as below 我已经分配了以下课程

@property (strong, nonatomic) MyViewController *myViewController;

myViewController =[[MyViewController alloc]initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
myViewController.userDetailsDict=userDetailsDict;
[self.navController pushViewController:self.myViewController animated:FALSE];

if i build the same application from Xcode 6, then i don't see any issue, it works fine. 如果我从Xcode 6构建相同的应用程序,那么我看不到任何问题,它可以正常工作。

Has any one faced an issue of similar kind. 有没有人遇到过类似的问题。 Any Help ? 有帮助吗?

That warning appears as a result of having NSZombieEnabled enabled in your build scheme (see linked question). 该警告是由于在构建方案中启用了NSZombieEnabled而导致的(请参阅链接的问题)。

At some point, [MyViewController numberOfSectionsInTableView:] is being called when MyViewController no longer exists - there were no more references to the object so it was deallocated. 在某个时候,当MyViewController不再存在时[MyViewController numberOfSectionsInTableView:]被调用-不再有对该对象的引用,因此将其释放。


As for why this happens on Xcode 5 and not Xcode 6, this is likely a result of your app's configuration or state in the simulator compared to the device - for example, does one environment contain data or settings that the other does not? 至于为什么在Xcode 5而不是Xcode 6上发生这种情况,这可能是与设备相比,您的应用程序在模拟器中的配置或状态的结果-例如,一个环境是否包含另一个环境所不包含的数据或设置?

From your code, I can see that MyViewController is probably a UITableViewDataSource . 从您的代码中,我可以看到MyViewController可能是UITableViewDataSource Does one device/simulator contain table view data that the other does not? 一个设备/模拟器是否包含另一个没有的表视图数据? If so, that is why the error would appear in one environment but not the other. 如果是这样,这就是为什么该错误将在一个环境中而不在另一个环境中出现的原因。 It would appear in both, but only one has the necessary settings/configuration in order to trigger the method being called. 会同时出现在两者中,但是只有一个具有必要的设置/配置才能触发被调用的方法。

In order to resolve the problem, you need to monitor the object lifecycle of MyViewController - that is, when is it created, when is it accessed and when is it/might it be released. 为了解决该问题,您需要监视MyViewController的对象生命周期-即何时创建,何时访问,何时释放/可能释放它。 At some point your view controller is being released when you still want to use it. 在某些时候,仍要使用视图控制器时将其释放。 This StackOverflow answer provides an excellent guide on how to use Instruments to track down and fix these sorts of errors. 这个StackOverflow答案提供了有关如何使用Instruments来跟踪和修复这类错误的极佳指南。

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

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