NSNotificationCenter的帖子导致“EXC_BAD_ACCESS”例外 [英] Post of NSNotificationCenter causing "EXC_BAD_ACCESS" exception

查看:84
本文介绍了NSNotificationCenter的帖子导致“EXC_BAD_ACCESS”例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIViewController 将自身添加到默认中心:

A UIViewController adds itself to the default center:

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(editFood)
 name:@"editFood"
 object:nil];

然后一个 UITableView 委托NSObject发布一个 NSNotification

Then a UITableView delegate NSObject posts a NSNotification:

[[NSNotificationCenter defaultCenter]
 postNotificationName:@"editFood"
 object:self];

在运行时,它会出现 EXC_BAD_ACCESS 异常。

During run time it get a EXC_BAD_ACCESS exception.

defaultCenter 是否在某个地方发布?当我从UIViewController向UIViewController发布通知时,同样的概念也有效,但这不重要,对吗?

Is the defaultCenter getting released somewhere? The same concept works when I post a notification to a UIViewController from a UIViewController, but that shouldn't matter, right?

推荐答案

您的一位订阅者已被取消分配。确保在dealloc中调用 [[NSNotificationCenter defaultCenter] removeObserver:self] (如果不是更早)。

One of your subscribers has been deallocated. Make sure to call [[NSNotificationCenter defaultCenter] removeObserver:self] in your dealloc (if not sooner).

这篇关于NSNotificationCenter的帖子导致“EXC_BAD_ACCESS”例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆