How to safely removeObserver (Swift)

后端 未结 2 987
生来不讨喜
生来不讨喜 2021-02-19 21:23

I have added an observer

override func viewDidLoad()
{
    super.viewDidLoad()

    NSNotificationCenter.defaultCenter().addObserver(self, selector:\"selector na         


        
2条回答
  •  星月不相逢
    2021-02-19 22:01

    I think you should use code

    NSNotificationCenter.defaultCenter().removeObserver(self)
    

    Explain: You have mistake here: You are using NSNotification & NSNotificationCenter so you have to using this code above to remove observe. you have use code for KVO to remove observer so it will wrong.

    More detail you can read at here. Key-Value-Observing

提交回复
热议问题