- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1) {
return NO;
}
else {
return YES;
}
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1) {
return NO;
}
else {
return YES;
}
}
我的tableView中有2个部分。我希望我的tableViewcells只在第一部分移动(而不是第二部分)。目前,如果我将tableCell拖到第二部分,它会崩溃。
答案 0 :(得分:2)
我认为你正在寻找这种方法 -
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
if (proposedDestinationIndexPath.section != 0)
{
return sourceIndexPath;
}
return proposedDestinationIndexPath;
}
它会限制您仅在第0部分中移动行。如果您尝试将第0行中的行移动到1,它将返回单元格的上一个索引路径