如何拖动 - 在NSTableView中移动一行? [英] How Do you Drag-Move a Row in NSTableView?

查看:346
本文介绍了如何拖动 - 在NSTableView中移动一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果是 iOS 项目,让用户拖动移动所选行将会比较容易。我认为它是像

If it were an iOS project, letting the user drag-move the selected row would be relatively easy. I think it's something like

- (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 {
    // ...
}

如何使用 NSTableView iOS)(如果我有基于单元格的表格)在 Mac OS 中? Apple,Inc.允许用户拖动项目的一个示例项目是 image-browser ,这不是很有帮助,因为它不涉及NSTableView控件。您是否使用 canDragRowsWithIndexes :atPoint?我没有得到很多搜索匹配与canDragRowsWithIndexes。如果我运行搜索NSTableView重新排序,我得到命中排序表项。

How do you do it with NSTableView (not UITableView in iOS) in Mac OS if I have a cell-based table? One sample project by Apple, Inc. that lets the user drag items is image-browser, which doesn't quite help because it doesn't involve an NSTableView control. Do you use canDragRowsWithIndexes:atPoint? I don't get many search hits with canDragRowsWithIndexes. If I run a search for "NSTableView reorder," I get hits for sorting table items.

感谢您的建议。

推荐答案

使用这些方法:

- (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 by Corbin Dunn is a little old but should get you there well.

这篇关于如何拖动 - 在NSTableView中移动一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆