Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Shaun Johnson1,214 Points
Want to add text field to bottom of TableView cell array
I'm using a TableViewController and need the user to be able to add cells. One solution is to have a custom text field at the bottom of the cell array. I'd rather not transition to a new view.
Any recommendations for how to accomplish this?
Nick Sint4,208 Points
How you want to tackle this may depend on how much input the user has to enter for each cell. If we assume each cell in the TableView has only 2-3 entries (say First Name and Last Name), then this can be easily done. If the user has to add alot of input, then perhaps a new screen should be presented modally.
Keeping to the assumption that the user will be inputting data into this TableView, I would recommend adding a button and the required UITextFields either on top OR below your TableView (depending on the design/purpose of the TableView).
In addition, for the code make sure a property is setup (lets assume its an Array for now) that will represent the data to be stored and used by the TableView. The count (i.e. number of rows) the TableView will use should be the count on this Array property. Each time the button is pressed, the IBAction called should add the new entry into the property, clear the textfield and call [tableView reloadData] so that the tableView is instantly refreshed and updated.
Hope this helps.