I'm basically trying to add a UITextField to a UITableViewCell upon tableView:commitEditingStyle:forRowAtIndexPath:. On insert, I want to add a UITextField over the existing cell.
I setup the textField with something like this:
-(void) setUpIndexField {
inputField = [[UITextField alloc] init];
inputField.textAlignment = UITextAlignmentCenter;
inputField.borderStyle = UITextBorderStyleRoundedRect;
inputField.keyboardType = UIKeyboardTypeNamePhonePad;
inputField.delegate = self;
}
Then in commitEditingStyle, I have something such as:
- (void)tableView:(UITableView *)tv
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [indexPath row];
if (editingStyle == UITableViewCellEditingStyleInsert) {
if (row == 0) {
UITableViewCell *cell = [tv cellForRowAtIndexPath:indexPath];
inputField.frame = [tv cellForRowAtIndexPath:indexPath].frame;
[cell.contentView addSubview:inputField];
[inputField becomeFirstResponder];
return;
}
// more code etc.
}
When I click on the Insert accessor (+), the textField does indeed get plopped onto the screen, but no where near the cell that's clicking it. It goes off into a random part of the UIView, not the actual cell for the indexPath at where the + was clicked.
Insight on where I went wrong and how I can place the UITextField onto the cell where the + was clicked would be ideal.