gpt4 book ai didi

iphone - 如何防止 UITableViewCell 被移离它自己的部分?

转载 作者:可可西里 更新时间:2023-11-01 06:23:40 25 4
gpt4 key购买 nike

我的 UITableView 有 3 个部分。只有第二部分的单元格是可移动的:

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
BOOL canMove = NO;
if (indexPath.section == 1) {
canMove = YES;
}
return canMove;
}

但是,第二部分(最初包含 A``B``C 单元格)中的单元格 (B) 可以移动到第一部分(最初包含仅 T 单元格):

enter image description here

如何确保单元格在其自己的部分内移动?

最佳答案

我想这会解决你的问题

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
if( sourceIndexPath.section != proposedDestinationIndexPath.section )
return sourceIndexPath;
else
return proposedDestinationIndexPath;
}

来自苹果 documentation

This method allows customization of the target row for a particular row as it is being moved up and down a table view. As the dragged row hovers over a another row, the destination row slides downward to visually make room for the relocation; this is the location identified by proposedDestinationIndexPath.

关于iphone - 如何防止 UITableViewCell 被移离它自己的部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11118423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com