我正在尝试在 iPhone 中创建一个地址簿,类似于 iPhone 地址簿。当我想创建一个新联系人时,在输入值UITextField
以输入电话号码时,它正在创建一个新的单元格TableView
。我已经尝试了下面的代码,但它正在创建多个单元格。
(void)textFieldDidBeginEditing:(UITextField *)textField
{
UITableViewCell *parentCell = (UITableViewCell *)[self.tview indexPathsForSelectedRows]; NSIndexPath *currRow = [self.tview indexPathForCell:parentCell];
[self addRow:currRow text:textField.text];
}
(void)addRow:(NSIndexPath *)indexPath text:(NSString *)text
{
NSIndexPath *nextRow;
if(indexPath.section==0)
i++;
nextRow = [NSIndexPath indexPathForRow:i-1 inSection:indexPath.section];
[self.tview beginUpdates];
// [self.tview reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tview insertRowsAtIndexPaths:[NSArray arrayWithObject:nextRow] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tview endUpdates];
}