拖曳在NSTableView上删除重新排序的行 [英] Drag & Drop Reorder Rows on NSTableView

查看:206
本文介绍了拖曳在NSTableView上删除重新排序的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否有一个简单的方法设置一个NSTableView,以允许它重新排序它的行,而不需要编写任何粘贴板代码。我只需要它能够在一个表格内部进行。编写pboard代码时,我没有问题,除非我确定我看到Interface Builder有一个切换到这个地方/看到它默认工作。



谢谢

解决方案

如果你看看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屋!

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