UITableView 删除表格单元写法

来源:互联网 发布:淘宝旺旺名称在哪里看 编辑:程序博客网 时间:2024/06/05 18:39

 

- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
            forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSDictionary *section = [data objectAtIndex:indexPath.section];
        if (section) {
            NSMutableArray *content = [section valueForKey:@"content"];
            if (content && indexPath.row < [content count]) {
                [content removeObjectAtIndex:indexPath.row];
            }
        }
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
 else if (editingStyle == UITableViewCellEditingStyleInsert) {
        NSDictionary *section = [data objectAtIndex:indexPath.section];
        if (section) {
            // Make a local reference to the editing view controller.
            EditingViewController *controller = self.editingViewController;
            NSMutableArray *content = [section valueForKey:@"content"];
            // A "nil" editingItem indicates the editor should create a new item.
            controller.editingItem = nil;
            // The group to which the new item should be added.
            controller.editingContent = content;
            controller.sectionName = [section valueForKey:@"name"];
            controller.editingTypes = [section valueForKey:@"types"];
            [self.navigationController pushViewController:controller animated:YES];
        }
    }
}

//那一行是要自己添加的 然后把新加那一行的属性设置成UITableViewCellEditingStyleInsert就行了