如果是 iOS 项目,让用户拖动移动选定的行会相对容易。我认为这就像
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (BOOL)tableView:(UITableView *)tableview canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
// ...
}
如果我有基于单元格的表,如何使用 Mac OS 中的 NSTableView (不是iOS中的UITableView)? Apple,Inc。允许用户拖动项目的一个示例项目是图像浏览器,这不太有帮助,因为它不涉及NSTableView控件。你使用 canDragRowsWithIndexes :atPoint吗?我没有使用canDragRowsWithIndexes获得很多搜索命中率。如果我搜索“NSTableView重新排序”,我会点击排序表项目。
感谢您的建议。
答案 0 :(得分:3)
使用以下方法:
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id < NSDraggingInfo >)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
- (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id < NSDraggingInfo >)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation
- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
Corbin Dunn的This guide有点老了但应该能帮到你。