显示控制器为presentViewController后,NSNotification停止工作

Rom*_*anS 1 nsnotifications uiviewcontroller ios

我添加了通知我的UIViewController进行捕获

  - (void)applicationWillResignActive:(UIApplication *)application:
Run Code Online (Sandbox Code Playgroud)

像这样

  - (void)viewDidLoad {

           [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:)
                                                 name:APP_RESIGN_ACTIVE_NOTIFICATION object:nil];
Run Code Online (Sandbox Code Playgroud)

它工作正常,但如果我显示其他控制器:

[self presentViewController:[[UINavigationController alloc] initWithRootViewController:view]
                   animated:YES
                 completion:nil];
Run Code Online (Sandbox Code Playgroud)

通知停止工作.我只删除了通知

 - (void)viewDidUnload {

     [super viewDidUnload];

     [[NSNotificationCenter defaultCenter] removeObserver:self name:APP_RESIGN_ACTIVE_NOTIFICATION object:nil];
Run Code Online (Sandbox Code Playgroud)

但是当我显示模态控制器时它没有被调用.

Rom*_*anS 5

抱歉,我在Base类中找到了一个删除通知的地方.

  • 谢谢!做了同样的事情. (2认同)