Thursday, October 09, 2008

Interface Builder strikes again

Just spent hours on a simple things I couldn't understand. I had a tab view controller in the interface builder, then in my own code in the project I had a class called FirstViewController. To reference this, I figured I should add a FirstViewController type view controller into the interface builder as well. Hilarity ensues as I now have a FirstViewController which is unbeknownst to me already being instantiated by the tab view controller (not sure how that works) so I had TWO instances of the same controller. At first I was really perplexed how on earth my instance variables are suddenly changing values in the debugger, then happened to notice that the address for "self" was different.

I just wanted my FirstViewController to be the delegate of a picker object, but now I had a different instance being the delegate and a different instance doing other things. After learning my mistake I was trying to hunt down the extra instance, and noticed that one of the tabs in the tab controller was already declaring itself a FirstViewController. Well, how to reference that, since the class isn't visible in MainWindow.xib along the other stuff? Took a bit longer to realize I can drag delegate references not only to the xib window, but also to certain visible controls! Felt like one of those Lucasarts adventure games where you miss a puzzle because you don't notice that a certain object was clickable.