接收NSNotification方法不调用

时间:2016-10-22 10:08:57

标签: ios iphone

我在下面用于注册通知: -

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AllSearch:) name:filter object:nil];


-(void)AllSearch:(NSNotification *)notification
{
NSLog(@"abc");    
}

我用这段代码发布通知: -

[[NSNotificationCenter defaultCenter] postNotificationName:filter object:nil];

但是“ AllSearch ”方法没有调用。

1 个答案:

答案 0 :(得分:0)

plz检查你必须先添加addObserver的代码

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AllSearch:) name:filter object:nil];

befor postNotification

[[NSNotificationCenter defaultCenter] postNotificationName:filter object:nil];