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.

iOS

Shaun Johnson
Shaun Johnson
1,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?

Peter Pult
Peter Pult
8,095 Points

Hi, can you specify your needs by providing some code or skribbles of what you want to achieve? Because in my opinion you'd add a cell with a button in the last row of the table. I can help you further if you give me some more information. :)

Are you using storyboards or using code?

Shaun Johnson
Shaun Johnson
1,214 Points

Hi Guys,

Peter: I was hoping I could drop an element into the storyboard, at the end of the TableView. But no luck. Marshall: I'm using storyboards.

Thx, Shaun

Peter Pult
Peter Pult
8,095 Points

Tell me what you want to achieve within your app not what you want to do in the storyboard. See the answer from Ryan Ackermann, is this what you are looking for?

Are you using a static UITableView or a dynamic one?

2 Answers

Nick Sint
Nick Sint
4,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.

Is this kinda what your asking for?

List Mockup

Shaun Johnson
Shaun Johnson
1,214 Points

Ryan: yes, exactly. Thank you for your visualization.