我有一个基于标签的应用程序的标签上的UIViewController,这挂钩的UIApplicationDelegate。我希望通过UIApplicationDelegate来处理应用程序事件,但是我的UIViewController中没有获取到它们,它的方法没有被调用。
除了在UIViewController的接口声明中钩住它之外,我还应该做什么?
@interface TestViewController : UIViewController<UIApplicationDelegate>
@end其他的代理都是作品,我可以处理它们,除了这个,UIApplication和它的代理应该有一些微不足道的‘技巧’,但我找不到。
谢谢!
发布于 2013-01-10 08:48:48
如果您需要一个类而不是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方法中的观察者。
https://stackoverflow.com/questions/14249043
复制相似问题