iphone - Objective-C - NSNotificationCenter 放在哪里?

标签 iphone objective-c

我有一个 NSNotificationCenter 选择器,

放在哪里?在委托(delegate)中(如果是,那么在哪里?)在 Controller 中?

将方法放在哪里。

我需要释放 NSNotificationCenter 吗?

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceNotificationReceived:) name:UIApplicationDidBecomeActiveNotification object:nil];



- (void)deviceNotificationReceived:(NSNotification *)notification
{
    [self.soundMgr endInterruption];
}

最佳答案

deviceNotificationReceived: 方法必须是 addObserver: 参数的实例方法。在这个实例中是 self,所以你的方法应该在同一个类中。

您不应该释放 NotificationCenter,因为您没有创建或保留它。

你的问题有点难懂,你问的是这个吗?

关于iphone - Objective-C - NSNotificationCenter 放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7679635/

相关文章:

iphone - 如何在 iPhone 中播放 URL 中的视频

iphone - iOS RestKit 认证

ios - 委托(delegate)通过父 View Controller 和嵌入式 View Controller 捕获了什么?

html - WKWebview加载本地html文件并深层链接进入目标页面

iphone - 如何在不平滑任何内容的情况下放大 UIImage?

iphone - NSMutableArray 没有正确添加对象?

ios - linphone 编译问题(刚从 git 下载)

ios - 我想在 NSDateComponents 类中获得四分之一的值(value)

ios - 将行动态添加到 UItableView,并为按钮保留最后两行

objective-c - Quartz 事件服务/事件水龙头是否已弃用?