我正在开发一个 iPad 应用程序,其中一个屏幕有一个包含多个部分的嵌入式表格 View 。每个部分都由其自己的数组(array1 和 array2)填充。
我创建了一个按钮,将此表置于编辑模式。但是,我需要改变我的
$tableView:commitEditingStyle:forRowAtIndexPath
以某种方式确定所选行位于哪个部分,并从关联数组中删除该条目。有人有什么想法吗?
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if(editingStyle == UITableViewCellEditingStyleDelete){
//This is the line i need to change...
[array1 removeObjectAtIndex:indexPath.row];
[myTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
最佳答案
看起来您需要从正确的数组中删除该行...在这些部分上使用 switch 语句可能会起作用(但前提是有一定数量的部分,您似乎表明有)
因此,在从数组中删除对象的地方,请确保根据该部分从正确的数组中删除它。
switch (indexPath.section) {
case 0
[array0 removeObjectAtIndex:indexPath.row];
break;
case 1
[array1 removeObjectAtIndex:indexPath.row];
break;
}
等等
关于iphone - 从具有多个部分的 UITableView 中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6469323/