2012-07-18 21 views
5

Aquí está el error que estoy recibiendoNSNotification EXC_BAD_ACCESS

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

En esta línea

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

En el archivo AsyncImageView.m.

El error detiene el código, pero si continúo en el depurador, congela Xcode y lo apaga. ¿Cómo puedo solucionar este problema?

+0

¿Cómo se declaran 'userInfo'? – Kjuly

+0

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

Respuesta

3

Pruebe el código de abajo, debería estar bien:

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

que funciona sino que también tengo un nuevo AsyncImagView.m y la línea se convirtió en este' [[NSNotificationCenter defaultCenter] postNotificationName: AsyncImageLoadDidFinish \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t objeto: _objetivo \t \t \t \t \t \t \t \t \t \t \t \t \t \t userInfo: [[userInfo copia] autorelease]]; ' – BigT

+0

@BigT Lo sentimos, no soy muy claro lo que said..Have resolviste el problema ?? – Kjuly

+0

Sí, tengo. Esa línea funcionó pero actualicé AsyncImageView.m y esa línea estaba ahí en su lugar. Ambos trabajan. – BigT

15

En init debe registrar, y en dealloc Debe registrarse la ONU!

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

O

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