ios - Mensaje de NSNotificationCenter que causa la excepción "EXC_BAD_ACCESS"
objective-c iphone (2)
Uno de sus suscriptores ha sido desasignado. Asegúrese de llamar a [[NSNotificationCenter defaultCenter] removeObserver:self] en su dealloc (si no antes).
Un UIViewController agrega al centro predeterminado:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editFood)
name:@"editFood"
object:nil];
Entonces, un delegado UITableView NSObject publica una NSNotification :
[[NSNotificationCenter defaultCenter]
postNotificationName:@"editFood"
object:self];
Durante el tiempo de ejecución obtiene una excepción EXC_BAD_ACCESS .
¿ defaultCenter está defaultCenter el defaultCenter alguna parte? El mismo concepto funciona cuando publico una notificación a un UIViewController desde un UIViewController, pero eso no debería importar, ¿no?
EXC_BAD_ACCESS puede suceder incluso después de verificar que dealloc existe así:
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self]
}
Lo anterior resolverá el problema la mayor parte del tiempo, pero aparentemente mi causa fue que indirectamente estaba agregando el observador con un selector: establecido en nil siguiente manera:
[NSNotificationCenter.defaultCenter addObserver:self
selector:nil
name:notificationName
object:nil];
... así que cuando EXC_BAD_ACCESS algo con ese notificationName , se produjo EXC_BAD_ACCESS .
La solución fue enviar un selector que realmente señala algo.