Combining multiple UITextFields and a UITableView in a nice way for an iPhone app: part 2

My last blog post was about creating a form for an iPhone application by combining multiple UITextFields in a UITableView. I outlined the problems with this kind of screens. The first problem is the destruction of data already entered when scrolling the field off screen and secondly, app crashes when the field with focus is scrolled off screen and you touch inside another textfield. The solution I proposed was to nest the UITableView inside a UIScrollview. After receiving feedback I came up with a second solution:

  1. extend a UITableViewController instead of implementing UITableviewDataSource and UITableViewDelegate yourself
  2. disable reuse of cells by using a unique cell identifier:
  3. NSString *CellIdentifier = [NSString stringWithFormat: @"Cell%i", indexPath.row];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    ..

    }

The UITableViewController handles scrolling into view when the keyboard is shown quite nicely. Using the unique identifier will prevent a cell and it’s content to be reused. And I had to agree to some of the feedback: using a UIScrollView to nest a tableView is kind of a hack.

There is a down side to this: UITableViewControllers don’t like to be combined with other view controllers, so you have to use a NavigationController or TabBarController to offer further interaction possibilities. I tried to, but never managed nicely to have for instance a UIToolBar over the UITableView.

Try it out and let me know what you think!

Download XCode project TestTableViewWithKeyboard2 with demo using UITableView to create a form.

6 thoughts on “Combining multiple UITextFields and a UITableView in a nice way for an iPhone app: part 2

  1. Pingback: Implementing a Data Entry UI on iPhone with Action Button « GQAdonis

  2. The simplest way I found from one website is to put an NSString variable for every textfield and update its value from the textfield text in the (- (void)textFieldDidEndEditing:(UITextField *)textField) that the textfield delegate will call. Then in every textfield creation code in (cellForRowAtIndexPath) you will put the text of this textfield to be the value of its NSString variable.

  3. this approach will lead to performance issues when your tables gets larger.
    the purpose of the cell identifier is make it easy/possible to re-use cells,
    what you’re doing is the opposite.

    your problem is not the fact cells get re-used, but you’re missing the
    point on the concept ‘DataSource’.
    You are storing data in the tableview itsself, while this should be done
    in your data-model, managed through the contoller object.

    one way is to keep an array that references the data for entry.

  4. your approach looks better. But, can you give a sample code or an example of doing this.

    Also, I did not understand your words(ou are storing data in the tableview itsself, while this should be done
    in your data-model, managed through the contoller object.)??

    Now I am storing the data in variables declared in the controller, is this wrong?

  5. Hi @arri,

    well the question is when to use a datasource? When filling in any value, or when the save button is touched. Right now I choose to have a separate way of storing temporary values, namely in the preserved cells and only update the datasource when the save button is hit.

    Yes this is not good for performance, but hey who’s gonna build a form on an iPhone with 50, 100 or 200 fields? So I think that problem is limited

    @ali, @arri means that on the change of a UITextField, UIButton etc. you store this value immediately in a temp array or evey as you are trying, into variables declared in the controller. Just think about when you really use/persist these values.

  6. Becoming a data entry specialist may not exactly be the dream job you’ve always hoped for, but there are some very good reasons why you may want to consider this position while you are looking for that dream job, going to school or simply supplementing your family’s income.`

    Latest article on our very own web portal
    <,http://www.beautyfashiondigest.com/eye-makeup-for-blue-eyes/

Comments are closed.