我有一个 UITableView 正在为用户处理核心数据 o 添加他们自己的单元格......但我希望他们能够按照他们想要的方式重新排序 TableViewCells......我现在使用代码但是每当重新排序时,假设我去添加另一个单元格,它将返回常规状态...如果您迷路了,请看下面的图片...
下面是代码:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) // Don't move the first row
return NO;
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
id ob = [_devices objectAtIndex:destinationIndexPath.row];
[_devices replaceObjectAtIndex:destinationIndexPath.row withObject:[_devices objectAtIndex:sourceIndexPath.row]];
[_devices replaceObjectAtIndex:sourceIndexPath.row withObject:ob];
}