What's the better way to addObserver/removeObserver with NSNotificationCenter?

前端 未结 5 1411
孤城傲影
孤城傲影 2020-12-08 15:07

I used to addObserver in viewDidLoad: and removeObserver in dealloc:. Code:

- (void)viewDidLoad
{
    [su         


        
5条回答
  •  攒了一身酷
    2020-12-08 15:39

    Don't forget NSKeyValueObservingOptionInitial. I use it with viewWillAppear/viewWillDisappear so my UI is always up-do-date, even if I hide that view controller, saving resources because I will not update it until is shown again.

提交回复
热议问题