相关疑难解决方法(0)

commitEditingStyle的问题 - 删除表中的单元格

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

以及删除单元格时如何设置动画.

为了我下面的代码,但哪些不起作用请帮助这样做.

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



    }   
}
Run Code Online (Sandbox Code Playgroud)

经过更多的研发后,我建立了新的代码,并成功运行

- (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]; 
}
Run Code Online (Sandbox Code Playgroud)

}

-(void)tableReload{
    [tbl reloadData]; …
Run Code Online (Sandbox Code Playgroud)

iphone xcode uitableview

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

iphone ×1

uitableview ×1

xcode ×1