开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜