如何在UIViewController中处理UIApplicationDelegate方法?

Tom*_*Tom 3 uiviewcontroller uiapplicationdelegate ios

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

在UIViewController的接口声明中将它连接起来我该怎么办?

@interface TestViewController : UIViewController<UIApplicationDelegate>
@end
Run Code Online (Sandbox Code Playgroud)

其他代表是作品,我可以处理它们,除此之外,UIApplication及其代表应该有一些琐碎的'技巧',但我找不到.

谢谢!

rma*_*ddy 9

如果您需要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];
Run Code Online (Sandbox Code Playgroud)

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

不要忘记dealloc在类的方法中删除观察者.