2
如何使用NSNotificationcenter的对象属性
有人可以告诉我如何在NSNotifcationCenter上使用对象属性。我希望能够使用它将整数值传递给我的选择器方法。 这就是我在UI视图中设置通知侦听器的方式。好像我要传递一个整数值,我不确定用nil替换什么。 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveEvent:) name:@"myevent" object:nil]; - (void)receiveEvent:(NSNotification *)notification { // handle event NSLog(@"got event %@", notification); } 我从另一个这样的类调度通知。该函数传递了一个名为index的变量。我想以某种方式触发此通知。 -(void) disptachFunction:(int) index { int pass= (int)index; [[NSNotificationCenter defaultCenter] postNotificationName:@"myevent" object:pass]; //[[NSNotificationCenter defaultCenter] postNotificationName:<#(NSString *)aName#> object:<#(id)anObject#> }