0
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)oldPath toIndexPath:(NSIndexPath *)newPath {

    if(oldPath.section == newPath.section && oldPath.row == newPath.row) return;

    NSMutableArray * group = (NSMutableArray *) self.groups;
    NSMutableArray *gItems = [group objectAtIndex:oldPath.section];
    NSDictionary *item  = [gItems objectAtIndex:oldPath.row];
    [gItems removeObjectAtIndex:oldPath.row];
    gItems = [group objectAtIndex:newPath.section];
    [gItems insertObject:item atIndex:newPath.row];

    [self.tableItems moveRowAtIndexPath:oldPath toIndexPath:newPath];    
}

试图在部分之间移动行。但是每次运行时它都会崩溃[self.tableItems moveRowAtIndexPath:oldPath toIndexPath:newPath],我做错了什么?提前泰。

4

2 回答 2

2

你有一个“off by one”错误:

if (newPath.row >= gItems.count) {
    [gItems addObject: item];
} else {
    [gItems insertObject: item atIndex:newPath.row];
}
于 2012-08-22T04:10:23.437 回答
0

发现了问题....只需删除[self.tableItems moveRowAtIndexPath:oldPath toIndexPath:newPath];它就可以了。

于 2012-08-22T04:48:40.607 回答