0
我正在嘗試在iPhone中創建一個類似於iPhone通訊簿的通訊錄。當我想要創建新聯繫人時,在輸入UITextField
中的值以輸入電話號碼時,它將在TableView
中創建一個新單元格。我已經嘗試了下面的代碼,但它正在創建多個單元格。當我點擊已經在iOS的uitableviewcell中的文本框時如何創建一個新的單元格?
(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];
}
您必須保存條目形成文本字段成MutableArray並給予細胞的數量部分作爲[數組計數]。在您退出FirstResponder的函數中,只需重新加載表格,隨着陣列數量的增加,您的細胞數量也會增加 – superGokuN