2012-07-18 9 views
5

は、私がAsyncImageView.mファイルでNSNotification EXC_BAD_ACCESS

Thread 1:EXC_BAD_ACCESS (code=2, address=0xb7ffffc) 
この行で

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

を取得していますエラーです。

エラーはコードを停止しますが、デバッガで続行するとXcodeがフリーズしてシャットダウンします。この問題を解決するにはどうすればよいですか?

+0

どのようにして 'userInfo'を宣言したのですか? – Kjuly

+0

'\t \t NSMutableDictionary *ユーザー情報= [NSMutableDictionary dictionaryWithObjectsAndKeys: \t \t \t \t \t \t \t \t \t \t画像、AsyncImageImageKey、 \t \t \t \t \t \t \t \t \t \t URL、AsyncImageURLKey、 \t \t \t \t \t \t \t \t \t \tはnil]; ' – BigT

答えて

3

は、以下のコードを試してみてください、それは大丈夫でなければなりません:

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

または:INITで

NSDictionary * userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:..., nil]; 
[[NSNotificationCenter defaultCenter] postNotificationName:AsyncImageLoadDidFinish 
                object:target 
                userInfo:userInfo]; 
[userInfo release]; 
+0

動作しますが、私はまた、新しいAsyncImagView.mを持って、ラインがこの' [[NSNotificationCenter defaultCenter] postNotificationNameになった:AsyncImageLoadDidFinish \t \t \t \t \t \t \t \t \t \t \t \t \t \t \tオブジェクト:_target \t \t \t \t \t \t \t \t \t \t \t \t \t \tのUserInfo:] [[のUserInfo]自動リリースコピー]; ' – BigT

+0

@BigT申し訳ありませんが、私はあなたが問題を解決しsaid..Haveかについて非常に明確ではありませんよ? – Kjuly

+0

はい。その行は機能しましたが、私はAsyncImageView.mを更新し、代わりにその行がそこにありました。どちらも動作します。 – BigT

15

あなたが登録する必要があり、かつにdeallocであなたが国連登録する必要があります!

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

OR

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