NSNotification观察器处于didFinishLaunchingWithOptions
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newShipCome:) name:kNewShipNotifaction object:nil];
我想在另一个ViewController中删除observer。
我在我的一个ViewController 中做到了这一点
[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
但仍然不起作用。有人知道怎么做吗?
感谢
您需要删除AppDelegate的observer,因为您在removeObserver:
方法中传递了不正确的对象。
代替:
[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
用途:
[[NSNotificationCenter defaultCenter] removeObserver:[[UIApplication sharedApplication] delegate] name:kNewShipNotifaction object:nil];