【问题标题】:tableview deleting rows issuetableview删除行问题
【发布时间】:2012-06-19 01:40:10
【问题描述】:

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

-(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];
        }

谢谢

【问题讨论】:

    标签: ios uitableview row delete-row


    【解决方案1】:

    使用此方法并将其替换为您的:

     -(void)tableView:(UITableView *)TableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
     {
    
       if (editingStyle == UITableViewCellEditingStyleDelete) 
       {
          [myarray removeObjectAtIndex:indexPath.section];
            [Table reloadData];
       }
     }
    

    【讨论】:

    • 它不起作用,我需要该方法来区分第一行标签 100(也是 0 部分)和第二行标签 200(也是 1 部分)和第三行标签 300(也是 2 部分)。所以想法是,如果我的 aux 等于删除的行,那么,从数组和 tableview 中删除它......但我不知道该怎么做这!!...而且 i
    猜你喜欢
    • 2014-10-21
    • 1970-01-01
    • 2013-12-20
    • 2016-12-25
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多