Objective-C: Where to remove observer for NSNotification?

前端 未结 14 1676
北海茫月
北海茫月 2020-11-29 19:37

I have an objective C class. In it, I created a init method and set up a NSNotification in it

//Set up NSNotification
[[NSNotificationCenter defaultCenter] a         


        
14条回答
  •  盖世英雄少女心
    2020-11-29 19:57

    In my opinion, the following code makes no sense in ARC:

    - (void)dealloc
    {
          [[NSNotificationCenter defaultCenter] removeObserver:self];
          [super dealloc];
    }
    

    In iOS 6, there's also no sense in removing observers in viewDidUnload, because it has been deprecated now.

    To sum up, I always do it in viewDidDisappear. However, it depends on your requirements also, just like @Dirk said.

提交回复
热议问题