滑动即可删除动画杀死线程

时间:2014-01-03 16:55:45

标签: ios objective-c uitableview

我对iOS编程很陌生,当我添加滑动以删除基本教程应用程序的功能时,它在我使用默认命令时崩溃。目前,我从NSMutableArray中删除了它连接并重新加载数据的对象:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        //[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self.toDoItems removeObjectAtIndex:indexPath.row];
        [tableView reloadData];
    }  

这个问题是我在删除时没有得到任何类型的动画。有关如何解决此问题的任何建议都是受欢迎的。

1 个答案:

答案 0 :(得分:2)

首先删除数据对象,然后删除行

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [self.toDoItems removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}
相关问题