iPhone xcode - Best way to control audio from several view controllers
I am pretty new to iPhone programming.
I have a navBar with three views. I need to control audio from all of the views. I only want one audio stream to play at a 开发者_如何学编程time. I was thinking that it would be smart to let my AppDelegate have an instance of my audioplaying class and let the three other views use that instance to control the audio. My problem is that I don´t know how my views can use the audioplaying class in my AppDelegate.
Is this the best approach and if so, how? Is there a better way?
The cleanest way would probably be to implement a singleton that you could access from all your view controllers (e.g. [[MYAudioController sharedController] theAudio]
). It's also possible to access it in your app delegate (e.g. [(MYAppDelegate *)[[UIApplication sharedApplication] delegate] theAudio]
, but I tend to think it's a bad idea to make view controllers dependent on the app delegate.
精彩评论