UITableView 的拖動排序,本質上是編輯模式下的 moveRow 行為,但也需要同步更新資料來源。


[_tableView setEditing:flag animated:YES];
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
Goods *goods = _goodsAry[sourceIndexPath.row];
[_goodsAry removeObject:goods];
[_goodsAry insertObject:goods atIndex:destinationIndexPath.row];
}
這樣畫面排序與資料模型才會一致。