Tuesday, April 20, 2010

Custom Cells for Iphone Table View

Lets say you've added a nice new View XIB file, and thrown on a UITableView using the Interface Builder's Library tool.
And now you want to create a custom cell, how do you go about it? After scouring through several blogs and sites I couldn't quite figure out how to create just a custom cell:

I always ended up adding a new View XIB file, grabbing the UITableViewCell from the Interface Builder Library, dropping it in and getting this:

That's one massive cell and not very useful. So, this is how you really do it and its so simple you'll wonder why you didn't immediately get it yourself.
1. Add a new View XIB file, lets call it CustomCell.
2. In the Interface Builder in the window titled CustomCell.xib notice that by default a UIView has been added.
3. Select the UIView that was added by default and hit delete.
4. Now grab UITableViewCell from the Library and drop it into the CustomCell.xib window,
just like you would in the View Window.

5. Voila! You now have just a UITableViewCell and can customize it as you please.

Jake's blog post about SubViews and Table Views and the following reference cover how to implement the code to populate and handle these custom cells:
http://www.e-string.com/content/custom-uitableviewcells-interface-builder

No comments:

Post a Comment