拖动&在 NSTableView 上删除重新排序行 [英] Drag & Drop Reorder Rows on NSTableView
问题描述
我只是想知道是否有一种简单的方法可以设置 NSTableView 以允许它重新排序其行而无需编写任何粘贴板代码.我只需要它能够在一个表中内部执行此操作.我编写板代码没有问题,除了我相当确定我看到 Interface Builder 在某处有一个切换/看到它默认工作.这似乎是一项足够常见的任务.
I was just wondering if there was an easy way to set an NSTableView to allow it to reorder its rows without writing any pasteboard code. I only need it to be able to do this internally, within one table. I have no issue writing the pboard code, except that I'm fairly sure that I saw Interface Builder have a toggle for this somewhere / saw it working by default. It certainly seems like a common enough task.
谢谢
推荐答案
如果你看一下 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.
这篇关于拖动&在 NSTableView 上删除重新排序行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!