Editing a UITextField inside a UITableViewCell fails

The answer by Brian M. Criscuolo is the closest, however its still not quite right - in my usage of SDK2.2.1 I find that I have to do the following:

To your UITableViewDelegate (which is often your UITableViewController) add both of the following:

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}

and:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    return UITableViewCellEditingStyleNone;
}

and:

- (void)viewDidLoad {
[super viewDidLoad];

    // do any other customisation here
self.uiTableView.editing = true;
}

If you don't put the top two delegate methods, the above will cause the delete icons next to each row, and the indentation of each row.

You shouldn't need to do anything with textfield delegates as Brian indicated (unless you have multiple rows and you want to respond to a didSelectRowAtIndexPath: event - which you don't seem to get while in edit mode - then you will need to also do as he suggests).

By the way - this seems fixed in SDK3.0 (although subject to change I guess)


I spent a lot of time on this but I finally think that I have it nailed.

The trick is that the table needs to be editable (i.e., its editing property needs to be set to YES). The good news is that you are now able to move the insertion point. Sometimes the magnifying glass doesn't appear or follow but your gesture always seems to work.

Does this still qualify as a bug? Perhaps. At the very least Apple's SDK documentation should be updated. I've raised a bug report with Apple to cover this (rdar://6462725).


Thanks to this post, I've been able to successfully get this to work properly in my app.

Something to add, however:

If you set your table to be editable, you'll likely get different behavior than you expect (indenting, editing widgets, no disclosure indicators, etc.). This surprised me but here's how to best deal with it:

In your UITableView delegate, implement:

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}

Then, in your UITableViewCell's implementation, set your UITableView to be editable ONLY when you're actually editing:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    ((UITableView *)[self superview]).editing = YES;
...
}

and disable editing when editing is done:

- (void)textFieldDidEndEditing:(UITextField *)textField
{
...
    ((UITableView *)[self superview]).editing = YES;
}

This will ensure that your table isn't in editing mode when you're not editing the cell, keeping things working smoothly.

Thanks!

Brian M. Criscuolo Mark/Space Inc.