我在每个单元格中都有一个UITextfield,我为其分配一个等于当前行号的标签。在UITableviewcell里面UITextfield返回的错误行删除后
cell.textfield.tag = indexPath.row;
我需要indexpath.row当用户结束编辑文本框。我在这里面临
-(void) textFieldDidEndEditing:(UITextField *)textField{
CustomCell *cell = (CustomCell *) [[textField superview]superview];
if([cell isKindOfClass:[UITableViewCell class]]){
//NSIndexPath *indexPath = [Table indexPathForCell:cell];
int row = textField.tag;
NSLog(@"indexpath: %d",row);
NSString *str = [datasource objectAtIndex:row]; //get exception here
.............. }
问题是,当我删除使用deleteRowsAtIndexPaths
一排,然后结束编辑最后一个单元格,我拿错标签号,因为数据源不包含元素索引处。此外,我不能使用indexPathForCell:
,因为如果我的正在编辑文本字段的单元格不在屏幕上,它将返回空值。
我能做些什么来获得正确的标签号码?我不想重新加载表格,因为它没有任何动画。什么可以替代?任何建议都是值得欢迎的。谢谢。
您是否正在删除此标记中的行'[tableView BeginUpdates]'&'[tableView endUpdates]'? – 2013-03-22 07:05:37
是的,我在做这些标签。 – NightFury 2013-03-22 07:06:44
不要使用indexPath.row来分配标签,你可以定义你的值。 – iphonic 2013-03-22 07:06:55