4

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

除了在我的 UIViewController 的接口声明中连接它之外,我应该怎么做?

@interface TestViewController : UIViewController<UIApplicationDelegate>
@end

其他代表是作品,我可以处理它们,除此之外,UIApplication 及其代表应该有一些微不足道的“技巧”,但我找不到。

谢谢!

4

1 回答 1

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];

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

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

于 2013-01-10T00:48:48.123 回答