Thursday, 19 February 2009

iPhone Interface Builder madness...

Hi!

I've been meaning to mention this for a while... and this has just happened to me again I guess the time is as good as any to mention it!

Basically: if you use XCode to create a New Project, based on Tab Bar Application... as soon as you try adding some items with activated UIAction responders, you're going to get an exception like this when starting the app... which is not a good thing. :)


'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ....'


When this happens, you're the victim of a really stupid bug in Interface Builder/Cocoa.

I wonder if this sort of problem is enough to put-off novice developers from using Interface Builder... that would be a shame.

Anyways: the solution to this problem is as follows...

  1. From Interface Builder, select MainWindow.xib

  2. Within the Tab Bar Controller, select each of the two View Controller items in turn... and for each one:

    1. Press Cmd-2

    2. In the window that appears, click on the right-most button with a (i) mark on it

    3. ... and in the Class combo box, specifiy the class to be FirstViewController... (the two items are both wrongly set to be UIViewController!)

Save your XIB file, rebuild the system, and all will then work!

The above steps are explained (obliquely!) here:

Very basic problem with Tab Bar Application and Interface Builder

What surprises me is how little Apple fans complain about hideous bugs like this. :)

Pete