2012-06-16 67 views
1

我试图在视图中删除正确的行时遇到问题。我有3个动态创建单元格分组的表格视图,并且,我正在使用编辑模式。当在每个部分中添加更多行并删除它们时,一切正常,但是当我尝试删除特定行时,它总是删除最后一行。假设我已经添加了行1,2,3(除了原来的行),我想删除数字2,它总是删除数字3.我还有一个方法,为每个新创建的行自动创建一个标记。 。我怎样才能通过删除问题?有任何想法吗?我知道我必须以某种方式识别删除行的代码中,以这个工作......每个部分都有一排,100随后200和300 ......这是我的代码:tableview删除行问题

-(void)tableView:(UITableView *)TableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
    int i=0; 
    for (i=0; i<myarray.count; i++) 
    { 
     UITableViewCell *aux=[myarray objectAtIndex:i]; 

     if (aux.tag >= 101 && aux.tag < 200 && indexPath.section==0) { 
      [myarray removeObjectAtIndex:i]; 
      [Table reloadData]; 
     } 
     if (aux.tag >= 201 && aux.tag < 300 && indexPath.section==1) { 
      [myarray removeObjectAtIndex:i]; 
      [Table reloadData]; 
     } 
     if (aux.tag >= 301 && indexPath.section==2) { 
      [myarray removeObjectAtIndex:i]; 
      [Table reloadData]; 
     } 

感谢

回答

0

使用此方法,用你的替换:

-(void)tableView:(UITableView *)TableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     [myarray removeObjectAtIndex:indexPath.section]; 
     [Table reloadData]; 
    } 
} 
+0

它didn't工作,我需要该方法,以便在第一列标签100之间进行区分(即也是0部)和第二行标签200(这也是1部分)和第三行标记300(也是2部分)。所以这个想法是,如果我的aux等于删除的行,然后,从数组中删除它,也是tableview ...但我不知道如何做到这一点!! ...和我 Japa