Objective-C-将NSNotificationCenter放在哪里? [英] Objective-C - where to put the NSNotificationCenter?

查看:49
本文介绍了Objective-C-将NSNotificationCenter放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSNotificationCenter选择器,

i have an NSNotificationCenter selector,

放在哪里?在控制器中(如果是,那么在哪里?)?

where to put it ? in the delegate (if yes then where?) in the controller?

方法的放置位置.

我需要取消分配NSNotificationCenter吗?

do i need to dealloc the NSNotificationCenter ?

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



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

推荐答案

deviceNotificationReceived:方法必须是addObserver:参数的实例方法.在这种情况下为self,因此您的方法应位于同一类中.

The deviceNotificationReceived: method must be an instance method of the argument to addObserver:. It is self in this instance, so your method should go in the same class.

您不应发布NotificationCenter,因为您没有创建或保留它.

You should not release the NotificationCenter, as you did not create or retain it.

您的问题有点难以理解,这是您要问的吗?

Your question was a little hard to understand, is this what you were asking?

这篇关于Objective-C-将NSNotificationCenter放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆