且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

拖动&在 NSTableView 上删除重新排序行

更新时间:2021-11-04 07:15:27

如果你看一下 IB 中的工具提示,你会看到你引用的选项

If you take a look at the tool tip in IB you'll see that the option you refer to

- (BOOL)allowsColumnReordering

控制,好吧,列重新排序.除了用于表格视图的标准拖放 API 之外,我认为没有其他方法可以做到这一点.

controls, well, column reordering. I do not believe there is any other way to do this other than the standard drag-and-drop API for table views.

(2012-11-25)

答案是指 NSTableViewColumns 的拖放重新排序;虽然这是当时公认的答案.近 3 年过去了,这似乎并不正确.为了使信息对搜索者有用,我将尝试给出更正确的答案.

The answer refers to drag-and-drop reordering of NSTableViewColumns; and while it was the accepted answer at the time. It does not appear, now nearly 3 years on, to be correct. In service of making the information useful to searchers, I'll attempt to give the more correct answer.

没有允许在 Interface Builder 中拖放重新排序 NSTableView 行的设置.您需要实现某些 NSTableViewDataSource 方法,包括:

There is no setting that allows drag and drop reordering of NSTableView rows in Interface Builder. You need to implement certain NSTableViewDataSource methods, including:

- tableView:acceptDrop:row:dropOperation:

- (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id < NSDraggingInfo >)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation

- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard

还有其他一些问题可以相当彻底地解决这个问题,包括 this一个

There are other SO question that address this reasonably thoroughly, including this one

Apple 链接到 拖放 API.

Apple link to Drag and Drop APIs.