间歇性 EXC_BAD_ACCESS

发布于 2024-10-24 17:12:58 字数 1025 浏览 1 评论 0原文

我有以下代码,用于创建模式导航控制器并呈现它。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言 2024-10-31 17:12:58

乍一看,代码看起来(几乎)是正确的。但是您应该在某处发布内容,但不太可能因此而发生 ExcBadAccess。

因此,为了解决这个问题,我建议使用 NSZombies。 NSZombies 可以防止你的对象被释放,它们只是被标记为释放(即变成僵尸)。

  1. 打开 xcode (3.x) 侧栏中的 Executable
  2. 右键单击​​可执行文件并获取信息
  3. 打开 Arguments 选项卡
  4. 添加要在环境中设置的变量下的一个环境变量,
  5. 将其命名为NSZombieEnabled并将其值设置为YES。确保它已激活
  6. 在启用断点的情况下运行代码,直到调用僵尸对象

当您知道它发生在哪里时,您可以更好地调查它发生的原因。

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).

  1. Open the Executable group in your xcode (3.x) sidebar
  2. Do a right-click and Get Info on your executable
  3. Open the Arguments tab
  4. Add a environment variable under Variables to be set in the environment
  5. Name it NSZombieEnabled and set its value to YES. Make sure that it is activated
  6. Run your code with breakpoints enabled until the zombie object is called

When you know where it happens you can better investigate why it happens.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文