开发者

iPhone XCode programming: execute code when change tab in a tab bar application

开发者 https://www.devze.com 2022-12-24 02:25 出处:网络
I\'m developing a simple tab bar application for school. It has 3 tabs. One of them plays mus开发者_开发知识库ic in streaming and I would like to stop the music playing when the user changes the tab.

I'm developing a simple tab bar application for school. It has 3 tabs. One of them plays mus开发者_开发知识库ic in streaming and I would like to stop the music playing when the user changes the tab. Is this possible? and How? Thank you in advance!


Implement the UITabViewController delegate method:

– tabBarController:didSelectViewController:

And you should be able to do what you want. There's also

– tabBarController:shouldSelectViewController:

if you want to know before the tab changes.


As Carl says, this is possible. However, if I were to develop such application (and actually, I am), I would use the viewWillDisappear method of my UIViewController (and I am). That way you keep the logic separated between your implementations.

0

精彩评论

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