commitEditingStyle的问题 - 删除表中的单元格 [英] problem with commitEditingStyle -to delete cell in the table

查看:119
本文介绍了commitEditingStyle的问题 - 删除表中的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个部分表,其中包含该部分,我想删除特定的单元格交换并删除此单元格并从表中删除该单元格,并从数组中删除。

i have one section table which contain the section and i want to delete the perticular cell swap and delete this cell and remove that cell from table and also remove from the array.

以及如何在删除单元格时为其设置动画。

and how to animate that when the delete the cell.

下面的i代码但不起作用请帮助完成此操作。

for that i code below but which is not working please help to do this.

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

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [self.reports removeObjectAtIndex:indexPath.row];
        [tbl reloadData];
            [tbl deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath] 
                                  withRowAnimation:UITableViewRowAnimationFade];    



    }   
}

经过更多R& D然后我建立新代码并成功运行

After much more R&D then i build up new code and which is successfully Run

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


if (editingStyle == UITableViewCellEditingStyleDelete) {
    // Delete the row from the data source

    [[[self.reports objectAtIndex:indexPath.section] valueForKey:@"events"] removeObjectAtIndex:indexPath.row];
    [tbl deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationLeft];

[NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(tableReload) userInfo: nil repeats: NO]; 
}

}

-(void)tableReload{
    [tbl reloadData];  }


推荐答案

首先你不应该在从表中删除行之前重新加载表。其次,在你的情况下,你想在那个部分有多个部分和多行。那么,你的

Firstly you should not Reload table before deleting row from table. Secondly, in your case you have multiple sections and multiple rows in that section, I guess. So, your

[tbl deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath] 
                                  withRowAnimation:UITableViewRowAnimationFade];  

不起作用。

从数组中删除对象将起作用。您不必从表中删除行。只需重新加载表:

won't work.
Deleting object from array will work. You don't have to delete row from your table. Just reload table :

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

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [self.reports removeObjectAtIndex:indexPath.row];
        [tbl reloadData];
}  

但要注意你正在放置正确的indexNumber。

But do take care that you are putting the correct indexNumber.

这篇关于commitEditingStyle的问题 - 删除表中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆