我在基于选项卡的应用程序的选项卡上有一个 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/