在我的 iPad 应用程序中,我在一堂课上注册了一条通知:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(selectedList:) name:@"TTSelectedList" object:nil];
我的selectedList:
方法如下所示:
- (void)selectedList:(NSNotification*)notification
{
NSLog(@"received notification");
}
然后在另一个类(a UITableViewController
)中,我在选择一行时发布该通知:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"posting notification");
[[NSNotificationCenter defaultCenter] postNotificationName:@"TTSelectedList" object:nil];
}
我可以确认正在发布通知,因为“发布通知”已记录到控制台,但从未调用“已收到通知”,这意味着未收到通知并且未调用选择器。我无法弄清楚是什么原因造成的。
谢谢