How to tell the active view controller when applicationDidBecomeActive is called?

后端 未结 6 1296
孤独总比滥情好
孤独总比滥情好 2021-02-02 12:01

I feel I am missing a trick here...

I just want to call viewDidLoad or viewDidAppear on the current active view controller when applicationDidBecomeActive gets called, s

6条回答
  •  爱一瞬间的悲伤
    2021-02-02 12:57

    Instead of sending a notification from your app delegate, the OS sends a notification automatically that you can observe:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(initSongInfo)
                                                 name:UIApplicationDidBecomeActiveNotification
                                               object:nil];
    

    and of course make sure to stop observing sometime before or inside your dealloc method, by calling:

    [[NSNotificationCenter defaultCenter] removeObserver:self 
                                                    name:UIApplicationDidBecomeActiveNotification 
                                                  object:nil];
    

提交回复
热议问题