将通知推送到另一个视图控制器仅在视图处于活动状态时显示

时间:2014-11-07 05:37:59

标签: ios push-notification viewcontroller

通知仅在observer_ViewController处于活动状态时调用该函数

AppDelegate.m

[[NSNotificationCenter defaultCenter] postNotificationName:kNewShipNotifaction object:ship];

observer_ViewController.m

-(void)viewDidLoad{
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newShipCome:) name:kNewShipNotifaction object:nil];
} 
- (void)newShipCome:(NSNotification *)notifacation{
  [self updateNotifyWithShip:notifacation.object];
}

当我在另一个viewController中时,通知没有调用newShipCome:(NSNotification *)notification方法。当我切换到observer_ViewController时,该方法仍然没有被调用。

那么......当我不在observer_ViewController时,如何才能正确通知更新?

1 个答案:

答案 0 :(得分:0)

删除取消注册代码表单viewWillDisappear它将起作用