例如,当内存不足时,系统会发送一个 UIApplicationDidReceiveMemoryWarningNotification
通知。这就是苹果当时在其文档中所说的全部内容。但是这个通知从哪里来,发送到哪个方法呢?或者我在哪里以及如何注册我收到的通知?
最佳答案
在您希望接收通知的类的初始化代码中调用以下方法:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMemoryWarning:) name: UIApplicationDidReceiveMemoryWarningNotification object:nil];
这假设您的类还实现了 handleMemoryWarning 方法,如下所示:
- (void) handleMemoryWarning:(NSNotification *)notification
{
}
关于ios - 在哪里以及如何注册接收通知的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/740562/