Iphone 从具有多个节的UITableView中删除行
我正在开发一个iPad应用程序,其中一个屏幕有一个带有多个部分的嵌入式tableview。每个节由其自己的数组(array1和array2)填充 我创建了一个按钮,可将此表置于编辑模式。然而,我需要改变我的想法Iphone 从具有多个节的UITableView中删除行,iphone,ios,uitableview,syntax,Iphone,Ios,Uitableview,Syntax,我正在开发一个iPad应用程序,其中一个屏幕有一个带有多个部分的嵌入式tableview。每个节由其自己的数组(array1和array2)填充 我创建了一个按钮,可将此表置于编辑模式。然而,我需要改变我的想法 $tableView:committeeditingstyle:forRowAtIndexPath 以某种方式确定所选行所在的节,并从关联数组中删除该项。有人有什么想法吗 -(void)tableView:(UITableView *)tableView commitEditingSty
$tableView:committeeditingstyle: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];
}
}
像这样做。。。使用
NSInteger section = [indexPath section];
if (section == 0)
{
// write your code for deleting rows in your 1st section
}
if (section == 1)
{
// write your code for deleting rows in your 2nd section
}
// This is the idea...
看起来您需要从正确的数组中删除该行。。。在节上使用switch语句可能会起作用(但只有在有一定数量的节的情况下,您似乎指出有) 因此,如果要从数组中删除对象,请确保根据节将其从正确的数组中删除
switch (indexPath.section) {
case 0
[array0 removeObjectAtIndex:indexPath.row];
break;
case 1
[array1 removeObjectAtIndex:indexPath.row];
break;
}
等等
是确定所选单元格所需的方法
如果只想确定显示的实际节,可以使用indexPath.section
NSInteger section = [indexPath section];
indexPath变量具有属性行和节。因此,您可以:
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if(editingStyle == UITableViewCellEditingStyleDelete){
if (indexPath.section == 1) {
// do something
}
}
CommittedItingStyle的indexPath参数:。。。细胞培养方法。也许我误解了这个问题,你能澄清一下“从关联数组中删除它”是什么意思吗?你的表中每个部分都有一个数组吗?试试这个:
[[self.mainArrayList objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
谢谢所有的解决方案都有效,但切换方法将是实现这一点的最佳方法。
[[self.mainArrayList objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];