ios - 如何处理 UIViewController 中的 UIApplicationDelegate 方法?

标签 ios uiviewcontroller uiapplicationdelegate

我在基于选项卡的应用程序的选项卡上有一个 UIViewController,它连接了 UIApplicationDelegate。我想通过 UIApplicationDelegate 处理应用程序事件,但我没有在我的 UIViewController 中获取它们,它的方法没有被调用。

除了在我的 UIViewController 的接口(interface)声明中 Hook 它,我还应该做什么?

@interface TestViewController : UIViewController<UIApplicationDelegate>
@end

其他委托(delegate)是有效的,我可以处理它们,除了这个,UIApplication 和它的委托(delegate)应该有一些微不足道的“技巧”,但我找不到。

谢谢!

最佳答案

如果您需要应用委托(delegate)以外的类来响应各种应用程序事件,则让其他类注册各种应用程序通知。

例如处理app进入后台:

// Put this in the class that needs to deal with entering the background
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgrounding) name:UIApplicationDidEnterBackgroundNotification object:nil];

有关所有通知的列表,请参阅 UIApplication 的文档。

不要忘记在类的dealloc 方法中移除观察者。

关于ios - 如何处理 UIViewController 中的 UIApplicationDelegate 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14249043/

相关文章:

ios - 如何始终在 Safari 中打开 google plus 登录屏幕

ios - 如何复制 ios 版本的 iPhone?

iphone - NSLog InterfaceRotation 在模拟器上不起作用?

ios - 使用 setViewControllers 时,viewWillAppear、viewDidAppear 和 viewWillDisappear 不会在 iOS 5 上被调用

ios - 根据所选的 UITableViewCell 行执行 segue

ios - 如何提取和计算具有价格属性的对象数组的价格

ios - Swift 不会播放来自链接的音频 - iOS

c# - 获取对 UINavigationController 的引用

iphone - Xcode 4 : Missing File's Owner with Storyboard?

ios - 如何通过自定义 URL 将 "property-list"对象传递给 iOS 应用程序?