Static Table Cells in iOS

I have been fiddling with iOS lately, and I was working on a project which used a TableView with static cells.  The project uses Core Data and a Master-Detail View Controller, and when you create such a project in XCode, it populates the project with a bunch of code to do the Core Data interaction, which in my case was completely useless.  As I started to rip it out, my app started crashing with this error:

*** Terminating app due to uncaught exception 'NSUnknownKeyException',
 reason: '[<MasterViewController 0x725ea00> setValue:forUndefinedKey:]: this 
class is not key value coding-compliant for the key staticDataSource.'

After much searching, I found out that this error indicates that something in the NIB/Storyboard has an outlet called “staticDataSource” in the MasterViewController class. I looked through all of the outlets in my storyboard, and found nothing.  I grepped every file in the project for “staticDataSource” and found nothing.  I randomly tried adding a property to MasterViewController called staticDataSource (I made it an NSSet), and the app stopped crashing, but didn’t show my static cells.  Finally, in a random effort, I changed MasterViewController back into a UITableViewController subclass (I had changed it to a UIViewController), and everything worked perfectly.  So apparently, despite what you may read, static table views do in fact need a data source, and making your controller a subclass of UITableViewController automatically provides you with the needed property.

Advertisements

One thought on “Static Table Cells in iOS

  1. Reid

    You have no idea how long I just spent combing StackOverflow and trying solutions that didn’t work. This fixed my problem, too. THANK YOU!

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s