拖曳在NSTableView上删除重新排序的行 [英] Drag & Drop Reorder Rows on NSTableView
问题描述
谢谢
如果你看看IB中的工具提示,你会看到你提到的选项
- (BOOL)allowColumnReordering
控件,好吧,列重新排序。除了标准用于表格视图的拖放API 。
编辑: strong> (2012-11-25)
答案是指拖放重新排序 NSTableViewColumns
;而当时是被接受的答案。现在已经差不多3年了,不正确。为了使信息对搜索者有用,我将尝试给出更正确的答案。
没有可以拖放 NSTableView
在Interface Builder中的行。您需要实现一些 NSTableViewDataSource
方法,包括:
- 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
还有其他SO问题可以彻底解决,其中包括这一个
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.
Thanks
If you take a look at the tool tip in IB you'll see that the option you refer to
- (BOOL)allowsColumnReordering
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.
EDIT: ( 2012-11-25 )
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.
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
There are other SO question that address this reasonably thoroughly, including this one
这篇关于拖曳在NSTableView上删除重新排序的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!