My app uses video displayed by a view controller in a view (View 1) as a background for the app's menu/navigation. Buttons lay over the top of the video and depending on where the video is, the buttons navigate to different sections of the app. It works fine, until I navigate away to another section (View 2 etc) and then return to View 1. After that, the notifications crash in View 1:
[NSKeyValueObservance movieStateChangeCallback:]: unrecognized selector sent to instance 0x13e920 2012-10-27 08:50:04.830 AppName[13707:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSKeyValueObservance movieStateChangeCallback:]: unrecognized selector sent to instance 0x13e920'
Here are the notifications I'm adding to View 1's init method:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieStateChangeCallback:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
player is a property of View 1 that is declared thusly:
@property (strong) MPMoviePlayerController *player;
I realize that this probably means that the player is being deallocated? Everything else works fine when I return to View 1 including the video, it is just the notifications which crash.
View 1 is being re-initialized when the user returns to it.
I am using ARC.
If a view controller is not currently visible and a memory warning occurs, it will remove all of it's views. These are then recreated when it becomes visible again. You're not removing yourself from the notification center when View1 is being deallocated so it's still asking to receive notifications.
Try adding this to your View1 class :
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}