间歇性 EXC_BAD_ACCESS
我有以下代码,用于创建模式导航控制器并呈现它。
DetailViewController *content = [[DetailViewController alloc]initWithNibName:@"DetailView" bundle:nil];
content.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Close"
style:UIBarButtonItemStylePlain
target:content
action:@selector(closeButtonPress:)] autorelease];
UINavigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:content];
modalNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:modalNavController animated:YES];
[modalNavController release];
这在 99% 的情况下都可以正常工作,但在奇怪的情况下我会崩溃。
-[__NSCFType closeButtonPress:]: unrecognized selector sent to instance 0x5ca91d0
I have the following code that creates a modal navigation controller and presents it.
DetailViewController *content = [[DetailViewController alloc]initWithNibName:@"DetailView" bundle:nil];
content.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Close"
style:UIBarButtonItemStylePlain
target:content
action:@selector(closeButtonPress:)] autorelease];
UINavigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:content];
modalNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:modalNavController animated:YES];
[modalNavController release];
This works fine 99% of the time but on the odd occasion I get a crash..
-[__NSCFType closeButtonPress:]: unrecognized selector sent to instance 0x5ca91d0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
乍一看,代码看起来(几乎)是正确的。但是您应该在某处发布内容,但不太可能因此而发生 ExcBadAccess。
因此,为了解决这个问题,我建议使用 NSZombies。 NSZombies 可以防止你的对象被释放,它们只是被标记为释放(即变成僵尸)。
Executable
组获取信息
Arguments
选项卡要在环境中设置的变量
下的一个环境变量,NSZombieEnabled
并将其值设置为YES
。确保它已激活当您知道它发生在哪里时,您可以更好地调查它发生的原因。
The code looks (almost) correct at first sight. But you should release content somewhere, but it's unlikely that the ExcBadAccess happens because of this.
So to hunt this down I would suggest to use NSZombies. NSZombies prevents that your objects get deallocated, they are just marked as deallocated (i.e. turned into zombies).
Executable
group in your xcode (3.x) sidebarGet Info
on your executableArguments
tabVariables to be set in the environment
NSZombieEnabled
and set its value toYES
. Make sure that it is activatedWhen you know where it happens you can better investigate why it happens.