Ios 该行没有';删除时,在UITableView中不会消失

Ios 该行没有';删除时,在UITableView中不会消失,ios,uitableview,Ios,Uitableview,我正在用数据库中的文件名填充iOS表视图。一切都按预期显示在tableView中。当我删除它时,问题出现了,它删除了数据库中的条目,但条目不会在UITableView中消失。这是我的密码: - (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { i

我正在用数据库中的文件名填充iOS表视图。一切都按预期显示在tableView中。当我删除它时,问题出现了,它删除了数据库中的条目,但条目不会在
UITableView
中消失。这是我的密码:

- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {

        DBHandler *handler;
        [handler ResumeID:[mydataList objectAtIndex:indexPath.row]]; //mydataList contains the array that contains name of all the entries in the DB and is displaying them on the tableview.
        [mydataList removeObjectAtIndex:indexPath.row];
         NSLog(@"%ld",indexPath.row);



        // Animate the deletion from the table.
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

实际上,您正在将之前删除的值传递给
DBHandler
。检查代码

if (editingStyle == UITableViewCellEditingStyleDelete)
{
    DBHandler *handler ;
    [handler ResumeID:[mydataList objectAtIndex:indexPath.row]]; // Pass the object from the dataSource before deleting the object from the dataSource.

     [mydataList removeObjectAtIndex:indexPath.row]; // Remove object after passing it to the DBHandler
    NSLog(@"%ld",indexPath.row);
    // Animate the deletion from the table.
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

尝试此操作。

删除后请刷新视图
[tableView重新加载数据]

这是ios7的一个bug。。tablerow动画已损坏!我的解决办法是在TableViewRow动画之前将单元格淡出

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // hide cell, because animations are broken on ios7
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        [tableView cellForRowAtIndexPath:indexPath].alpha = 0.0;
    }

    [tableView deleteRowsAtIndexPaths:@[indexPath]
                     withRowAnimation:UITableViewRowAnimationMiddle];
}

不,OP的代码是正确的。您必须在更新表视图之前删除数据。@rmaddy,他实际上是在删除
[mydataList removeObjectAtIndex:indexPath.row]对象,然后将相同的对象句柄赋给
DBHandler
[handler ResumeID:[mydataList objectAtIndex:indexath.row]]看到这一点。这似乎是一个问题,但它并没有改变这样一个事实,即您必须在更新数据源之后(而不是之前)删除表视图中的行。是的,没错!这是我的错误。无论如何,谢谢你纠正我。根据需要更新你的答案。指出在从数组中删除对象之前需要更新
处理程序的问题。这太过分了。您只需要删除一行。删除一行后,重新加载视图。怎么会过度杀戮?OP的代码是正确的。只需调用
deleteRowsAtIndexPath
,而不是重新加载整个表。@LightYagami,这是一种很好的替代方法,尽管我一直在这样做,但它不会有任何帮助。感谢您的建议,下次在tableview附近编写代码时,请记住,干杯,表做了什么?任何东西你调试代码了吗?是否调用了
deleteRowsAtIndexPaths:
?是的,我已经完成了调试,deleteRowsAtIndexPaths得到了调用。但之后例外就来了。什么例外?你从来没有提到过例外。我的猜测是,在从表视图中删除行之前,您的数据源没有正确更新。在从数组中删除对象之前,您需要调用
handler ResumeID…
。顺便说一句-
handler
nil
,因此调用
ResumeID
不起任何作用。那么您发布的代码就不是真正的代码。发布真实代码。在您发布的代码中,您从未初始化
处理程序
变量。我在删除iOS 7下的行时没有任何问题。我不需要任何技巧来让它工作。