在我的应用程序中,用户可以使用编辑按钮和拖放来移动 UITableViewCell
行。
我不希望用户能够将单元格移动到第 0 行。我已经为我的 NSMutableArray
工作,如果该行为 0,则不要重新排列集合中的对象.但即使这样,可见表格仍然显示第 0 行的单元格。
如何以图形方式防止这种情况发生?
我试过以下方法:
-(NSIndexPath*)tableView:(UITableView*)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath*)sourceIndexPath toProposedIndexPath:(NSIndexPath*)proposedDestinationIndexPath
{
if(proposedDestinationIndexPath.row == 0)
{
return 1;
}
return proposedDestinationIndexPath;
}
但是当我尝试将第 1 行的单元格移动到第 0 行时,它会因 EXC_BAD_ACCESS
错误而崩溃。
最佳答案
您的做法是正确的。问题是 tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath
方法应该返回 NSIndexPath*
,但你返回一个整数。修复很简单:
if(proposedDestinationIndexPath.row == 0)
{
return [NSIndexPath indexPathForRow:1 inSection: proposedDestinationIndexPath.section];
}
关于ios - 如何防止将 UITableViewCell 移动到特定索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26362913/