NSNotification观察者在didFinishLaunchingWithOptions
中[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newShipCome:) name:kNewShipNotifaction object:nil];
我想在另一个ViewController中删除观察者。
我在我的一个ViewController
中完成了这个[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
但仍无效。有谁知道怎么做?
感谢
答案 0 :(得分:3)
你需要删除AppDelegate的观察者,你在removeObserver:
方法中传递了错误的对象。
而不是:
[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
使用:
[[NSNotificationCenter defaultCenter] removeObserver:[[UIApplication sharedApplication] delegate] name:kNewShipNotifaction object:nil];