I have a table view consisting of lots of fields, divided into sections, with the fields sourced from a database. I wish to support in-place editing of the text in the fields, so I create a text field for each row and add it to me cell:
[cell.contentView addSubview:myTextField];
I give the text field a fixed tag so that I can easily configure the cell:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
Item *item = [self itemWithIndexPath:indexPath];
UITextField *textField = (UITextField *)[cell.contentView viewWithTag:1000];
textField.text = item.name;
}
When the text field has been edited I need to update the database. I can set up a delegate on the text field to respond to the end of the editing, but I somehow have to find out which indexPath has been edited so that I can update the database appropriately.
How can I do this?
I suppose I could maintain a tag->IndexPath mapping that get’s updated each time I configure a cell, but that feels like overkill. Is my tired brain missing the obvious?
Thanks,
Tim
So, my brain started working: