The best way to do custom, reusable UITableViewCells

So it’s probably the most common thing you want to do in iOS development, and that’s to create a page which shows a scrollable list of items, that is, a UITableView. UITableView, of course, comes with 4 default table cell styles, which can accommodate basic needs, but almost inevitably, you want to do something that isn’t covered by the default types. Perhaps you want to give it a nice gradient background, or maybe you would like to support multiline detail text, or maybe you’d like to have images loaded remotely, on a background thread, in order to maintain maximal scrolling performance. Maybe you need to add a UITextfield or a UISwitch. The variations are endless. As are the ways that you can implement a solution.

So rather than go through the different ways we can accomplish this task, let’s just cut to the chase and show a great solution which gives us completely custom, flexible cells, which can be reused in multiple view controllers. Yes, that means there is no need to specify a File’s Owner on your UITableViewCell subclass, and no outlets to hook up into your view controller.

Here’s the recipe. We’ll use a list of menu items from a restaurant for our example: