选择 UITabBar 时调用方法?

发布于 2024-08-04 00:44:17 字数 159 浏览 6 评论 0原文

我目前正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁梦 2024-08-11 00:44:17

为了防止其他人遇到这个问题,我改为调用 'viewDidAppear' 链接到选项卡的视图控制器中的方法。

- (void)viewDidAppear:(BOOL)animated {
    // do stuff here    
}

这种灵魂对我来说更理想,因为我只想检查一个选项卡!

Just incase anyone else has this issue I instead called the 'viewDidAppear' method in the view controller which is linked to the tab.

- (void)viewDidAppear:(BOOL)animated {
    // do stuff here    
}

This soultion was more ideal for me as I was only wanting to check for one tab anyway!

半窗疏影 2024-08-11 00:44:17

如果您在某处实现了 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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文