iOS - 在选项卡更改时运行代码

标签 ios cocoa-touch uiviewcontroller uitabbarcontroller

我有多个选项卡,如果不停止,每个选项卡都会执行一些可能会干扰其他选项卡上的操作的操作。如果用户在转到下一个选项卡之前忘记关闭一个选项卡中的功能,我想知道当用户单击 UITabBarController 中的另一个选项卡时是否有办法从 UIViewController 运行代码块。

最佳答案

您应该在可以访问您的内容的业务逻辑的 View Controller 中实现UITabBarControllerDelegate协议(protocol)。因此,当用户尝试单击另一个选项卡时,您可以执行某些操作。

您很可能需要实现:

 – tabBarController:shouldSelectViewController:
 – tabBarController:didSelectViewController:

参见 documentations对于 UITabBarControllerDelegate。

关于iOS - 在选项卡更改时运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14079218/

相关文章:

iPhone应用程序: Overall Application Hierarchy & Architecture

ios - 如何计算给定一系列数字的一些点

iphone - UIPickerView 显示问号而不是 UIImageView 和 UILabel

iphone - 除非我手动将其设置为零,否则属性不会被释放。或者在 Instruments 中运行它

objective-c - 发现对早期 iOS 版本中不可用的方法的调用

ios - 释放与导航 Controller 关联的 View Controller

ios - presentViewControler 将所有 Controller 压栈

ios - Q :How to get CGPoint from NSConcreteValue?

ios - 资源文件大小超过 2GB 的企业应用程序

ios - 强制提前调用 iOS 设备上的后台任务到期处理程序以进行测试