tags:

views:

137

answers:

0

In the Contacts app's add/edit view, if you hit the 'Return' key in a field, you cycle through each of the UITextFields. These fields seem to be inside a UITableViewCell. What's a good way to do this?

When I have a series of UITextFields not inside a Table, I can invoke [self.view viewWithTag:tag] to get a list of the views and the use that to cycle through them. But within a table, I only get one view and I'm not sure how to convert this over.

 -(BOOL)textFieldShouldReturn:(UITextField *)textField {
    // Find the next entry field
    for (UIView *view in [self entryFields]) {
     if (view.tag == (textField.tag + 1)) {
      [view becomeFirstResponder];
      break;
     }
    }

    return NO;
}

/*
 Returns an array of all data entry fields in the view.
 Fields are ordered by tag, and only fields with tag > 0 are included.
 Returned fields are guaranteed to be a subclass of UIResponder.

 From: http://iphoneincubator.com/blog/tag/uitextfield
 */
- (NSArray *)entryFields {
    if (!entryFields) {
     self.entryFields = [[NSMutableArray alloc] init];
     NSInteger tag = 1;
     UIView *aView;
     while (aView = [self.view viewWithTag:tag]) {
      if (aView && [[aView class] isSubclassOfClass:[UIResponder class]]) {
       [entryFields addObject:aView];
      }
      tag++;
     }
    }
    return entryFields;
}