For my app's settings view controller, I want to have a table view with a bunch of options the user can tweak. Toggle switches, segues, steppers, etc.
What's the best way to accomplish this? Table views are quite simple in the case where each cell follows a simple layout. Maybe a title and some subtext. But in this case a cell may be one of, say, five layouts depending on what kind of setting is being changed.
Is the best way to handle this to subclass UITableViewCell, and in the tableView's cellForRowAtIndexPath:
, before you return the cell set a custom property like kind
to something like toggle
or label
? Then in the viewDidLoad
of that cell subclass set the cell up based on the kind
property?
Is this inefficient? Should I make a cell with all controls already on it, but hidden, then just enable them based on kind
? Should I have a subclass for each kind of cell with different controls that I want?
That's how I'm thinking about handling it. But is there a more preferred way? Is this inefficient because it doesn't have a necessarily predictable pattern from cell to cell?
I don't like the idea that I have to debug someone else's code if incase i didn't like something in it. That's why I try to write code on my own and then see if it fits my needs or not. If it doesn't then I would go and take a look at InAppSettingsKit.
What you have asked for is a very simple stuff and I have implemented in almost every app of mine i.e. UITableView with options.
this is how I would do it. You can do all this straight up in xcode.
I hope this helps. Here is one of my sample project settings screenshot. You cannot see header and footer that I had created.
Since you're using this for settings, have you considered InAppSettingsKit?
In cases where that may be overkill, I have resorted to creating a static tableview in a storyboard where I can layout each distinct setting and have design-time control over its appearance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With