在我的tableview中,我希望有一个特定的单元格信息,而其他人可以自由移动, 我阻止了我的细胞被移动购买其他细胞仍然可以在它下面移动。这个单元格不是我的数据模型的一部分,所以我真的必须将它保存在控制器层中。
因此,我正在寻找一种防止默认行为的方法。
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
if (destinationIndexPath.row == [tableView numberOfRowsInSection:0]-2) {
//prevent the move
}
else {
[[BNRItemStore sharedStore] moveItemAtIndex:sourceIndexPath.row toIndex:destinationIndexPath.row];
}
}
答案 0 :(得分:0)
您是否尝试过实施此委托方法?
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
答案 1 :(得分:0)
使用targetIndexPathForMoveFromRowAtIndexPath,如下所示,
// Allows customization of the target row for a particular row as it is being moved/reordered
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath {
if( proposedDestinationIndexPath is ok ) {
return proposedDestinationIndexPath;
} else {
return sourceIndexPath;
}
}