4

I have a UIBarButtonItem embedded in a navigation item. It is positioned using the storyboard and at some point during runtime, it disappears. I have discovered that it is being deallocated.

I could start browsing through my code, maybe doing a search for 'myButton = nil', to see if something is deliberately nilling it, for example. Then I decided to find out if there was an advanced debugging technique I could use for situations like this.

One approach I could use is to subclass UIBarButtonItem and put a breakpoint in dealloc, to see if a stack trace would provide anything useful about who is nilling my button.

Does anyone know of any cool LLDB features, or key value observing technique or some symbolic breakpoint I could set for this kind of thing?

The App does not crash, the button just disappears at a predictable point at runtime.

P.S. it is probably something simple, I am just asking to find out what debugging techniques y'all might be using for things like this.

1 Answers1

0

I think the button is not getting deallocated. The view hierarchy changes in such a way that it becomes invisible. To check it press the area and see if the associated function gets fired or not.

If you want to check the button is deallocated or not, you can profile your application through object allocations profiler. Check the profiler when bar button item disappeared. What profiler shows the bar button item count in persistent column will let you know that if it is there or not.

Second you can use Xcode view hierarchy feature. Open it when bar button item becomes disabled. If it is present in view hierarchy, it must be there.

Apurv
  • 17,116
  • 8
  • 51
  • 67
  • the button is definitely being deallocated. in fact, i found the root cause of the issue. a tap gesture on a random view is calling an action which subsequently assigned 'nil' to my button. –  May 21 '15 at 09:49
  • but the point of my question is, 'pretend i haven't found the reason why' - and 'what debugging method would you use to solved this simple problem'. –  May 21 '15 at 09:50
  • instruments is a little overkill i think, for something like this. –  May 21 '15 at 09:50