Monday, January 21, 2013

UITableViewCells and Forgotten Wisdom

I've been playing around with a new game for my daughter based on an old game called Electronic Detective. I'm actually making a version of it for her to play (since my old solid state system, for some reason, only plays about half a game before crashing out). I had originally planned on making everything fit onto a single screen (which would have been better on iPad, but I'm a sucker for pain which is why I'm making it for iPhone), but decided to be considerate and moved from a single UIViewController view to a new UITableView layout. But the new version of Xcode makes creating UITableViewCells a little, um, wonkier than I remembered.
NB: I'm sure this is all 1,000,00% easier with storyboards, but I'm not using them as I'd like to target devices more than 6 months old. And yes, that was some slight sarcasm.
The first thing I ran into is that when you add a UITableViewCell .h/.m to your project, it doesn't allow you to create a .XIB with it. You need to create the .XIB separately. Then, the thing I've learned, is that you need to set the class for the VIEW to be the new .h/.m class name you selected. Do not set the File Owner to be the new class - leave it as UITableViewCell.
If you don't do that and leave the view as the UITableViewCell or if you set the File Owner to be the new class, you're likely to run into a dreaded "this class is not key value coding-compliant for the key XXXX" error. This is not terribly useful but some searching on slashdot and other places guided me in the right direction. If you've come here because you searched for that and you're using UITableViewCells, then here is likely what you're seeing as a problem.
This is one of those problems that I continue to stumble upon as I work through things only periodically. I forget some of the tricks and tips I've learned previously. But as my spousal unit and I have decided that she will not be returning to her job at Lockheed-Martin (as they have recently changed their leave-of-absence policies denying her the ability to take a second year off to watch our illness-prone son), I need to start getting some more titles in the App Store - and quickly. Given that, I will be working more feverishly to get things completed and released and will be sharing far more on this blog than I have been of late. And I will hopefully be retaining more of this forgotten wisdom.
Wish me luck!