UITableView:如何禁用将项目拖动到特定行? [英] UITableView: how to disable dragging of items to a specific row?
问题描述
我有一个带有可拖动行的 UITableView,我可以添加/删除项目.数据源是一个 NSMutableArray.
I have a UITableView with draggable rows and I can add/remove items. The datasource is a NSMutableArray.
现在,如果我移动带有添加新功能"的行,应用程序会崩溃,因为数据源较小,因为尚未添加此类行.
Now, if I move the row with "Add new functionality" the app crashes because the dataSource is smaller since such row has not been added yet.
所以我修改了这段代码:
So I've modified this code:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row >= [dataList count]) return NO;
return YES;
}
现在我不能再移动它了.但是我仍然可以在这些行之后移动其他行,因此代码崩溃.
And now I can't move it anymore. However I can still move the other rows after such row and consequently the code crashes.
我该如何解决这个问题?有没有办法禁用拖动到"特定行,而不仅仅是从?
How can I solve this ? Is there a way to disable the dragging "to" specific rows and not only from ?
谢谢
推荐答案
这正是UITableViewDelegate
方法
-tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:
是为了.它适合你的目的吗?这是文档.
is for. Will it suit your purposes? Here's the documentation.
这篇关于UITableView:如何禁用将项目拖动到特定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!