2012-07-18 18 views
5

Qui è l'errore che sto ottenendoNSNotification EXC_BAD_ACCESS

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

Su questa linea

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

Nel file AsyncImageView.m.

L'errore arresta il codice, ma se continuo nel debugger, blocca Xcode e lo spegne. Come posso risolvere questo problema?

+0

Come hai dichiara 'userInfo'? – Kjuly

+0

'\t \t NSMutableDictionary * USERINFO = [dictionaryWithObjectsAndKeys NSMutableDictionary: \t \t \t \t \t \t \t \t \t \t immagine, 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

risposta

3

Prova il codice qui sotto, si dovrebbe essere a posto:

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

o:

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

che funziona, ma ho anche avuto un nuovo AsyncImagView.m e la linea diventato questo' [[NSNotificationCenter defaultCenter] postNotificationName: AsyncImageLoadDidFinish \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t oggetto: _target \t \t \t \t \t \t \t \t \t \t \t \t \t \t userInfo: [[userInfo COPIA] autorelease]]; ' – BigT

+0

@BigT dispiace, io non sono molto chiari su quello che said..Have hai risolto il problema ?? – Kjuly

+0

Sì, ho. Quella linea ha funzionato ma ho aggiornato AsyncImageView.m e quella linea era lì invece. Entrambi funzionano. – BigT

15

In init è necessario registrarsi, e in dealloc è necessario registrarsi un!

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

O

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