To quote a famous person:
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth.
Since all the other guesses were wrong, the only other source of the problem that I can think of is that you are calling objc_removeAssociatedObjects()
at some point. In your question you say that your code used to work, so we must assume that somewhere something changed, causing the execution path to suddenly take a different turn.
- Possibility 1: The execution path now goes through that call to
objc_removeAssociatedObjects()
where before it didn't. - Possibility 2: You already called
objc_removeAssociatedObjects()
before, but now you are passing a different value to the function.
It's impossible to say which one of those two it is.
You say in your comment that you do not pass the navigationItem
in question and ask for an explanation. Unfortunately I cannot provide one. With the knowledge I currently have, I must assume that either your claim or the Apple docs for the function are incorrect. Since objc_removeAssociatedObjects()
has worked for me in the past, I naturally tend to believe Apple :-)
I might ask: How did you verify that you do not pass the wrong object to the function? My suggestion: Add two NSLog
statements to the code, just before you call objc_getAssociatedObject()
and objc_removeAssociatedObjects()
, where you print the pointer of the object that you are passing to the two functions.