NSTableView:选择不可编辑的单元格而不是行 [英] NSTableView: selecting non-editable CELLS and not ROWS

查看:30
本文介绍了NSTableView:选择不可编辑的单元格而不是行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了其他帖子中建议选项的多种组合,但我似乎无法使用不可编辑的 NSTextFieldCell 填充基于单元格的 NSTableView 来选择 CELL 而不是行.

I've tried numerous combinations of suggested options from other posts, but I can't seem to get a cell-bassed NSTableView populated with non-editable NSTextFieldCell to select the CELL and not the row.

我试过了:

    [[col dataCell] setEditable:NO];
    [[col dataCell] setSelectable:YES];

    [col setEditable:YES];

并尝试过委托:

- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex;

- (BOOL)shouldFocusCell:(NSCell *)cell atColumn:(NSInteger)column row:(NSInteger)row;

允许选择单元格(而不是编辑文本)的原因是我允许用户双击单元格来执行导航功能.双击效果很好,但用户应该能够看到单击(甚至第一次单击)选择了单元格.但我得到的只是被选中的行,即使代表禁止这一点,也不会选择单元格.

The reason for permitting selecting of the cell (and not editing the text) is that I allow the user to double-click on the cell to perform a navigation function. Double-clicking works great, but the user should be able to see that a single click (or even the first click) selects the cell. But all I get is the row being selected, and even if the delegate inhibits this, no cell selection.

这是强制单元格以选择突出显示颜色绘制其背景的唯一方法吗?(看起来很hackish).

Is the only way to do this to force the cell to draw its background in the selection highlight color? (seems hackish).

顺便说一句,COLUMN 选择也是允许的.目前有效.

BTW, COLUMN selection IS permitted, too. That presently works.

有没有人有这个问题的经验?或者一些明智的猜测?

Anyone have any experience with this issue? Or some sage guesses?

斯蒂芬

推荐答案

听起来您正在尝试制作电子表格.这不是表格视图.

It sounds like you're trying to make a spreadsheet. That's not what a table view is.

表格视图是一个项目列表,每行一个,显示每个项目的一个或多个方面,每列一个.

A table view is a list of items, one per row, showing one or more aspects of each item, one per column.

在这种情况下,选择但不编辑单个项目的一个属性很少有意义.可能有它的用例(例如,能够在 iTunes 中仅选择和复制曲目的标题可能很方便),但这不是 NSTableView 和 NSOutlineView 适应的.

In that context, it seldom makes sense to select but not edit only one property of a single item. There may be use cases for it (might be handy to be able to select and copy only the title of a track in iTunes, for example), but it's not something NSTableView and NSOutlineView accommodate.

电子表格是非常不同的东西.每个细胞都是彼此的对等体;任何一个轴都不一定从属于另一个.电子表格可以用作表格(例如:商品、价格、数量、小计),但不绑定 NSTableView 的商品属性范例.

A spreadsheet is something very different. Every cell is a peer to every other; neither axis is necessarily subordinate to the other. A spreadsheet can be used as a table (e.g.: item, price, quantity, subtotal), but is not bound to the properties-of-items paradigm of NSTableView.

NSTableView 的 API 证明了这一点.请注意,表视图具有 selectedRowIndexesselectedColumnIndexes,但无法枚举用于标识所选单个单元格的列、行对.

NSTableView's API bears this out. Note that a table view has selectedRowIndexes and selectedColumnIndexes, but no way to enumerate the column,row pairs that would identify selected individual cells.

您最好实现自定义视图.您可能会很好地模拟 NSTableView 的数据源协议——例如,您可以使用 spreadsheetView:objectValueForColumnIndex:rowIndex:——但除此之外,您还有很多工作要做,尤其是实现编辑.

You're best off implementing a custom view. You'd probably do well to emulate NSTableView's data source protocol—you could have spreadsheetView:objectValueForColumnIndex:rowIndex:, for example—but otherwise, you have a lot of work ahead of you, particularly to implement editing.

不过,从长远来看,这是获得单个细胞选择的最好方法,也是唯一方法.

Long-term, though, it's the best way, and the only way to get individual-cell selection.

这篇关于NSTableView:选择不可编辑的单元格而不是行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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