选择 UITabBar 时调用方法?
我目前正在 iPhone 上编写一个应用程序,只是想知道是否有人知道调用函数的方法,但仅在选择选项卡时调用。
我有一个单独的视图控制器用于相关选项卡,我想调用一个函数,在选择选项卡时更新 GPS 位置。
如果有人可以提供帮助那就太好了:)
谢谢 - 詹姆斯
I'm currently writing a app on the iPhone and was just wondering if anyone knew a way to call a function but only when a tab is selected.
I have a separate view controller for the tab in question and I want to call a function which updates the GPS position when the tab is selected.
If anyone could help that would be great :)
Thanks
- James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了防止其他人遇到这个问题,我改为调用 'viewDidAppear' 链接到选项卡的视图控制器中的方法。
这种灵魂对我来说更理想,因为我只想检查一个选项卡!
Just incase anyone else has this issue I instead called the 'viewDidAppear' method in the view controller which is linked to the tab.
This soultion was more ideal for me as I was only wanting to check for one tab anyway!
如果您在某处实现了 UITabBarControllerDelegate 协议,并且将实现该协议的类设置为选项卡控制器的委托,则可以在按下选项卡时进行处理。这样您就可以在需要时调用正确的方法。参考位于此处;您可能需要的方法是 tabBarController:didSelectViewController:
If you implement the UITabBarControllerDelegate protocol somewhere, you can handle when a tab is pressed if you set the class that implements it as the tab controller's delegate. That way you can call the correct method when you need it. The reference is here; the method you probably need is tabBarController:didSelectViewController: