When should I remove observers? Error about deallocating objects before removing observers

后端 未结 4 507
清歌不尽
清歌不尽 2020-12-13 02:18

I am trying to use key-value observing in one of my classes. I register the observers in the init method and remove/deregister them in the dealloc, but I get the following e

4条回答
  •  伪装坚强ぢ
    2020-12-13 03:02

    The normal code looks something like this:

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

    Double check your signature of your dealloc method (Objective C is very unforgiving and will never warn you when you mess up the name of a method). For example, if your method name was "dealoc" (with one l), your dealloc would never be called.

    Otherwise, edit your question to include your dealloc reoutine.

提交回复
热议问题