-(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]
行时都会崩溃,我做错了什么? Ty提前。
答案 0 :(得分:2)
你有一个“一个一个”的错误:
if (newPath.row >= gItems.count) {
[gItems addObject: item];
} else {
[gItems insertObject: item atIndex:newPath.row];
}
答案 1 :(得分:0)
想出了问题....只需删除[self.tableItems moveRowAtIndexPath:oldPath toIndexPath:newPath];
,它就可以了。