I’m still very new to Objective C, and I was wondering something regarding viewDidDisappear.
I have an app that plays a sound (using AVAudioPlayer), and I want to stop the sound when the view is switched.
If I do this in my view controller implementation:
- (void)viewDidDisappear:(BOOL)animated {
[self.audioPlayer stop];
}
it works fine. But the small programmer in my brain is saying that I’m not using this correctly.
I’m pretty sure you are supposed to CALL viewDidDisappear with a boolean argument, rather than just specify (BOOL)animated; besides, it would be nice to have some animation in my view switching… then again, that might be a whole different discussion!
So, what am I doing wrong, and how would I correctly use this? Do I have to link the call a button action? Where is the correct play to actually declare the function itself?
Thanks.
I implement
viewDidDisappear:(BOOL)animatedEXTENSIVELY, along withviewWillAppear,viewWillDisappearandviewWillDisappearThe main reason to implement this method is to make your view controller to do something at the event, such asviewDidDisappearYou don’t call this method, but your app will call your view controller to do what’s implemented there. Since this is inherited method, as long as you make sure all the inherited implementation from the super class can be done, it’s great to implementviewDidDisappear. So, I suggest you to change your code to be like this: