Ben's right - but I found another, potentially fragile, way around that. I just discovered this because I was forever getting the "...was deallocated while key value observers were still registered with it"
I don't know why - but when I had addObserver in my init method, and removeObserver in my dealloc method - I was still getting the KVO was still being observed message. I stepped through and verified that my removeObserver was being called correctly.
I moved my addobserver into the viewDidLoad method instead, and that seemed to work.
I left a removeObserver in viewDidUnload and in dealloc; but I don't like that because it's not balanced. But under normal circumstances, my viewDidUnload doesn't get called - this is just protection in case I get a low memory notification.
But I can see potentially getting into the situation where a low memory event comes in, viewDidUnload gets called. If I then hit dealloc sometime after that (before I hit viewDidLoad again), I will call removeObserver twice!
So, I think I'll just keep it in my viewDidLoad, and my dealloc.
I still don't know why it doesn't work right if I do the addobserver in my init method.
dealloc
is not always called? Would it be safer to calladdObserver
ininit
and callremoveObserver
inviewDidUnload
- or this scheme would cause my view controller not to re-register after it is loaded once again after memory warning (which caused the view to get unloaded since it was not shown)? – Brecciate