Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Settings-style grouped table

So it's trivial to create a Settings style table on the iPhone. The problem is, they add a great deal of code as your Settings have a gamut of options/styled cells. One section might have a check list, another might have cells with accessory disclosures to drill down further, another might be labels with UITextFields.

My question here is, what's the cleanest way to go about creating this table. Do you typically create a subclass of UITableViewController and then subclass UITableViewCell for each different type of cells, and write supporting classes for those cells? Meaning if you have a Settings style table with 4 sections, all different types of cells, you will load 4 nibs into the table and import 4 class files? Programmatically set the frame, views, textfields and tag them for later access?

The answer(s) to this is probably subjective, but I'd like to know what you experts consider the most elegant approach to this common problem.

like image 1000
Coocoo4Cocoa Avatar asked Dec 04 '08 04:12

Coocoo4Cocoa


People also ask

What is UITableView in Swift?

A view that presents data using rows in a single column.

How do you add a footer in tableView?

To create a basic header or footer with a text label, override the tableView(_:titleForHeaderInSection:) or tableView(_:titleForFooterInSection:) method of your table's data source object. The table view creates a standard header or footer for you and inserts it into the table at the specified location.

How do I create a footer in Swift?

Using StoryBoard In UITableView You can drag UIView, it will set as FooterView if you have more then 0 prototype cell. After Drag you can see it in table view hierarchy as a subview. Now, you can add the label button on that View, you can also set IBAction into ViewController Class File.


2 Answers

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

I also recommend this to help corral your code: A technique for using UITableView and retaining your sanity

like image 154
August Avatar answered Sep 29 '22 08:09

August


I would rather set most of the settings 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, it will take quite a few rounds of "modify - build - test" in the iPhone Simulator to get this special table view laid out the way you want it.

I feel it's probably a bit easier to do all of these rough visual changes in IB, then load all of the custom UITableViewCell dynamically via their identifiers in code. You could then do one final round of tweaking on this code, if something that you want is not doable in IB.

like image 43
jpm Avatar answered Sep 29 '22 07:09

jpm