What is this about
I notice many many apps I use have a similar way of implementing form (sets). For example:
This is basically the same scheme used in the Settings app as well.
My problem
When I need to make something like this, I basically make a grouped UITableView
, define how many groups with how many fields each I have, etc. The cellForRowAtIndexPath
basically becomes a big switch statement which sets the right form field as accesoryView
. I make all the form fields in advance in the code and make sure they are set up properly.
However, I have this feeling that there must be a much better way. This feels like an awful lot of repetitive code. And code which I find very difficult to make pretty.
What I want
Ideally, I'd just like to write my form completely from Interface Builder, because it's really intuitive for me. So creating a UITableView
and it-s content in Interface Builder. Just making a form in IB is simple of course, but not while also putting the fields in a grouped tableview - which I do really want because it looks pretty and consistent.
Another option is something like the Settings bundles: I define the type and name of my fields, the code of the app renders the table, creates the field instances, etc.
I'm in search of something better because i开发者_如何学编程t seems quite odd to me that such a extremely common problem needs to be handled in such a complex way. Especially considering that so many of the common problems are already handled well. But on this problem, I can't find anything.
So: is my approach really the best way of displaying these kind of forms? Can parts be improved? Is there any way I've overlooked for the existing iOS libraries to help me?
A UITableView
really is the best way to go. You could use a UIScrollView
, but that will involve a lot more work since you lose out on the built in functions that UITableView
offers.
If you prefer to use the IB, which I completely understand, then you can create each UITableViewCell
in the IB, lay it out with objects, link up an IBOutlet
, and then include it that way into your UITableView
. This also makes it easy to set up actions and delegates for the objects you're using, e.g. UITextField
s and UISwitch
es.
精彩评论