Search code examples
iphoneiosuitableviewapplication-settings

Any code examples for using a UITableView to implement in-app settings?


Any code examples for using a UITableView to implement in-app settings?

That is where to get the iPhone settings app look and feel one custom builds the settings into a UITableView. So you you would custom set the sections and cells that get returned with switch type statements.

In particular interested in reviewing the coding approach for how to:

  • best configure the cellForRowAtIndexPath and didSelectRowAtIndexPath
  • how to handle those cells for which you want in cell editing (e.g. text)
  • those cells where you need to launch off into another screen to set a date/time for example
  • how to collect up parameters and pass back to calling rootViewController (in my case need to persist data out to Core Data persistence)
  • Note: using Core Data so not interested in using libraries such as InAppSettings [any feedback re whether such libraries might be ok appreciated at this SO question I created].

thanks


Solution

  • I am not sure if you can use the inappsettingskit for your needs. It is open source so you are free to modify the code as you wish, but it doesn't look as an out of the box solution.

    If you want to make these settings available in the settings app you will have to live with some workarounds for example saving NSDate AND getting a nice UI control to modify it: Use a textfield, there is no control specified which let's you pick a date. Have a look at Apple's documentation.

    So the last option will be coding. First of all, determine what kind of types you want to support. Then create custom TableViewCells which reflect those kinds. If some kinds do need some special way of editing, for example a color picker, you'll have to write those controllers as well. You set a cell into editing mode with the delegate method tableView:didSelectRowAtIndexPath and present the custom controller or get into editing directly for example a UITextField. A Slider is handled directly without any coding.

    The cells will need some kind of identifier so you can identify those in your model. A TableView and Core Data can interact with each other pretty well by using the NSFetchedResultsController. Create a simple window based app with a template and check the Use Core Data for Storage. The rootViewController illustrates how a tableView works together with Core Data. For your case it will be getting a bit more complicated as inserting a row will have to determine what kind of cell it should add.

    I think you should look into this and get back with some more specific questions.