5

这是我得到的错误

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

在这条线上

[[NSNotificationCenter defaultCenter] postNotificationName:AsyncImageLoadDidFinish
                                                        object:target
                                                      userInfo:[[userInfo copy] autorelease]];

在 AsyncImageView.m 文件中。

该错误会停止代码,但如果我继续使用调试器,它会冻结 Xcode 并将其关闭。我该如何解决这个问题?

4

2 回答 2

15

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

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

或者

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
于 2012-07-18T14:35:20.910 回答
3

试试下面的代码,应该没问题:

NSDictionary * userInfo = [NSDictionary dictionaryWithObjectsAndKeys:..., nil];
[[NSNotificationCenter defaultCenter] postNotificationName:AsyncImageLoadDidFinish
                                                    object:target
                                                  userInfo:userInfo];

或者:

NSDictionary * userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:..., nil];
[[NSNotificationCenter defaultCenter] postNotificationName:AsyncImageLoadDidFinish
                                                    object:target
                                                  userInfo:userInfo];
[userInfo release];
于 2012-07-18T14:30:13.833 回答