Ios 删除AppDelegate';在其他ViewController中创建观察者

Ios 删除AppDelegate';在其他ViewController中创建观察者,ios,object,nsnotificationcenter,Ios,Object,Nsnotificationcenter,NSNotification observer处于didFinishLaunchingWithOptions状态 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newShipCome:) name:kNewShipNotifaction object:nil]; 我想删除另一个ViewController中的观察者 我在我的一个ViewController中完成了此操作 [[NSNotific

NSNotification observer处于didFinishLaunchingWithOptions状态

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newShipCome:) name:kNewShipNotifaction object:nil];
我想删除另一个ViewController中的观察者

我在我的一个ViewController中完成了此操作

[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
但仍然不起作用。有人知道怎么做吗


谢谢

您需要删除AppDelegate的观察者,您在
removeObserver:
方法中传递了不正确的对象

而不是:

[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
使用:


您需要删除AppDelegate的观察者,您在
removeObserver:
方法中传递了不正确的对象

而不是:

[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
使用:


您需要删除AppDelegate的观察者,您在
removeObserver:
方法中传递了不正确的对象

而不是:

[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
使用:


您需要删除AppDelegate的观察者,您在
removeObserver:
方法中传递了不正确的对象

而不是:

[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
使用:



您好,Midhun,您知道如何从其他ViewController中删除observer吗?OtherViewController*vc=[[OtherViewController alloc]init];[[NSNotificationCenter defaultCenter]removeObserver:vc名称:@“测试”对象:nil];没有真正删除observer。不,它不起作用。您正在那里创建一个新对象。如果你想从同一个类pass self而不是vc变量中删除otherViewController的观察者,那么我有机会删除otherViewController的观察者吗?@Jenny说,你属于a类,需要删除B类的观察者。然后你需要将B的对象传递给类A。如果你在类A中并且需要移除它的观察者,你可以将self传递给移除的观察者:我猜singleton是将同一对象传递给另一个ViewController的方法,对吗?嗨Midhun,你知道如何从其他ViewController移除观察者吗?OtherViewController*vc=[[OtherViewController alloc]init];[[NSNotificationCenter defaultCenter]removeObserver:vc名称:@“测试”对象:nil];没有真正删除observer。不,它不起作用。您正在那里创建一个新对象。如果你想从同一个类pass self而不是vc变量中删除otherViewController的观察者,那么我有机会删除otherViewController的观察者吗?@Jenny说,你属于a类,需要删除B类的观察者。然后你需要将B的对象传递给类A。如果你在类A中并且需要移除它的观察者,你可以将self传递给移除的观察者:我猜singleton是将同一对象传递给另一个ViewController的方法,对吗?嗨Midhun,你知道如何从其他ViewController移除观察者吗?OtherViewController*vc=[[OtherViewController alloc]init];[[NSNotificationCenter defaultCenter]removeObserver:vc名称:@“测试”对象:nil];没有真正删除observer。不,它不起作用。您正在那里创建一个新对象。如果你想从同一个类pass self而不是vc变量中删除otherViewController的观察者,那么我有机会删除otherViewController的观察者吗?@Jenny说,你属于a类,需要删除B类的观察者。然后你需要将B的对象传递给类A。如果你在类A中并且需要移除它的观察者,你可以将self传递给移除的观察者:我猜singleton是将同一对象传递给另一个ViewController的方法,对吗?嗨Midhun,你知道如何从其他ViewController移除观察者吗?OtherViewController*vc=[[OtherViewController alloc]init];[[NSNotificationCenter defaultCenter]removeObserver:vc名称:@“测试”对象:nil];没有真正删除observer。不,它不起作用。您正在那里创建一个新对象。如果你想从同一个类pass self而不是vc变量中删除otherViewController的观察者,那么我有机会删除otherViewController的观察者吗?@Jenny说,你属于a类,需要删除B类的观察者。然后你需要将B的对象传递给类A。如果你在类A中并且需要移除它的观察者,你可以将self传递给移除的观察者:我猜singleton是将同一对象传递给另一个ViewController的方法,对吗?