Grouped table with settings

So, it’s trivial to create a settings stylesheet on the iPhone. The problem is that they add a lot of code, since your settings have a gamut of options / stylized cells. One section may have a checklist, the other may contain cells with information on accessories, and the other may be shortcuts with UITextFields.

My question here is what is the cleanest way to create this table. Usually you create a subclass of UITableViewController and then subclass UITableViewCell for each type of cell and write helper classes for these cells? If you have a stylesheet with 4 sections, all types of cells, will you load 4 tables into a table and import 4 class files? Programmatically set the frame, views, text fields and mark them for later access?

The answer to this question is probably subjective, but I would like to know what you, experts, consider the most elegant approach to this general problem.

+6
objective-c iphone cocoa-touch
source share
3 answers

The easiest way to do this is to simply add your controls during tableView: cellForRowAtIndexPath: method.

I also recommend this to help encode your code: Technique for Using a UITableView and Keeping Your Convenience

+6
source share

I would prefer to set most of the parameters that I can in Interface Builder, instead of writing a whole bunch of code to make the visual / layout just right. As you can imagine, the iPhone simulator will require quite a few rounds of "modification - assembly - test" to get this special presentation of the table as you want it.

I feel that it might be a little easier to make all these gross visual changes in IB and then dynamically load all custom UITableViewCell through their identifiers in code. You can then do one final round of customization on this code if something you want is not feasible in IB.

+1
source share

The Three20 library (extracted from the iPhone application for iPhone) has a set of ready-made cells that contain various controls.

(Not sure if you want to use them). Three20 suffers a little from “not invented here” and tries to subclass and expand everything, so adding it adds a lot of mess to your project. at least you can use it as an example.)

PS Your question prompted me to open “ What are your favorite UITableView / UITableViewCell tricks? ” In Stack Overflow, check it out for more tips.

+1
source share

All Articles