xcode - NSNotification EXC_BAD_ACCESS

标签 xcode exc-bad-access nsnotificationcenter

这是我得到的错误

Thread 1:EXC_BAD_ACCESS (code=2, address=0xb7ffffc)

在这条线上
[[NSNotificationCenter defaultCenter] postNotificationName:AsyncImageLoadDidFinish
                                                        object:target
                                                      userInfo:[[userInfo copy] autorelease]];

在 AsyncImageView.m 文件中。

该错误会停止代码,但如果我继续在调试器中,它会卡住 Xcode 并关闭它。我该如何解决这个问题?

最佳答案

在 init 中需要注册,在 dealloc 中需要取消注册!

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:AsyncImageLoadDidFinish  object:nil];

或者
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

关于xcode - NSNotification EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11543388/

相关文章:

iphone - 如何将 int 值从一个 View Controller 传递到 iPhone 应用程序中的下一个 View Controller

ios - glGetAttribLocation/glGetUniformLocation 返回 0,导致调用 glDrawArrays 时出现 EXC_BAD_ACCESS (iOS)

objective-c - 如何在 Objective-C 中添加观察者并在 Swift 3 中触发通知

ios - 滚动内部 UITableView 时处理 NSNotification

ios - CoreData : removal of 'didSave' notification immediately after save: call. 太快了?

php - 保护网络服务器上的文件并通过 iPhone 应用程序访问它们

ios - 我需要在 Nib 之间使用自定义转场

ios - 配置文件 "**"的应用 ID 为 "**",与 bundle ID "**OneSignalNotificationServiceExtension"不匹配

objective-c - 与结构对齐相关的 EXC_BAD_ACCESS?

c - 程序收到信号 : “EXC_BAD_ACCESS” ?