Iphone 如何防止UITableViewCell从其自己的分区移出?
我的Iphone 如何防止UITableViewCell从其自己的分区移出?,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我的UITableView有3个部分。只有第2部分中的单元格是可移动的: - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { BOOL canMove = NO; if (indexPath.section == 1) { canMove = YES; } return canMove; } 但是,第2部分(最初包含
UITableView
有3个部分。只有第2部分中的单元格是可移动的:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
BOOL canMove = NO;
if (indexPath.section == 1) {
canMove = YES;
}
return canMove;
}
但是,第2部分(最初包含a``B``C
单元格)中的单元格(B
)可以移动到第1部分(最初仅包含T
单元格):
如何确保单元格在其自己的分区内移动?我认为这将解决您的问题
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
if( sourceIndexPath.section != proposedDestinationIndexPath.section )
return sourceIndexPath;
else
return proposedDestinationIndexPath;
}
来自苹果
此方法允许为特定行自定义目标行
在表视图中上下移动行。随着划船
将鼠标悬停在另一行上,目标行向下滑动至
视觉上为搬迁腾出空间;这是确定的位置
通过ProposedDestinationIndepath