Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chrono1081

macrumors G3
Original poster
Jan 26, 2008
8,811
5,751
Isla Nublar
Hi guys,

I have an app I'm working on and I have a form with a segmented control at the top and based on the button selected on the segmented control it needs to hide certain text fields on the form.

When some of those text fields are hidden, the ones below the hidden fields need to move up and fill in the space the hidden fields left behind.

My question is is there an elegant way to do this using maybe constraints, or some property?

Or do you think it would be better to maybe dynamically load a new view based on the selection?

I haven't found much documentation suggesting how one may approach this.
 
I'm sure there is a Viewcontroller to do sort of what you want but that might require completely separate views so data the user has inputted might be lost in the transition.

I would suggest a Tableview, just because I use them a lot and might overlook better solution in favour of them. As the user switches segment test if the data that should be removed has a cell in the table and remove those cells, add in any that should be added. Tableview animates everything in to place for you.
 
I would suggest UICollectionView instead of UITableView. They are much more flexible
 
There's a library someone else made and posted on github that can handle all this stuff very well. If only this were Python or Ruby or Racket or any other language where adding third party libraries was trivial or I'd strongly recommend it (and no, Cocoa Pods isn't acceptable. Not at all. I tried that once. Ended up with a lot of compilation errors and just threw it out).
 
A tableview or collection view is one likely choice. Look at Settings.app and see if there's something in there that works the way you want to serve as a model. It all seems to be tableview based. There's also some apple sample code that shows various ways to add/remove rows dynamically.
 
An app I'm currently working with, decided to go with a scroll view and manually hiding fields not to be displayed and adjusting the frames for those they wanted to show in short mode. There isn't any animation between the two modes but that doesn't seem to be a big deal. The switch is at the top of scroll view.
 
Thanks guys for all of the suggestions :)

I'm not allowed to use any external libraries for this project (sorry I should have clarified that) but I'll give the other options a look.

Thanks again.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.