NSNotificationCenter with respect to ViewWillAppear and ViewWillDisapper

前端 未结 2 1642
南笙
南笙 2021-01-15 13:34

I have a simple viewController that I want to listen for UIKeyboardWillHideNotification. Therefore I have the following code:

- (void) viewWill         


        
2条回答
  •  感情败类
    2021-01-15 13:58

    To answer your direct question, dealloc will never be called while your view is still on screen unless you directly call it which you shouldn't be.

    dealloc will only be called when there are no strong pointers remaining that point to your viewController.

    As Anoop Vaidya suggests, it is totally doable to put removeObserver in dealloc and be confident that dealloc won't get called while your viewController is on screen, and if it does... well you have much bigger problems than removing an observer

    Edit: Since I can't actually reply to comments yet, when your viewController is off screen it is actually deallocated. It is then re-instantiated when it is called back on screen.

    Edit: I'm wrong

提交回复
热议问题