为什么只调用setObjectValue:nil时NSPopUpButtonCell显示正确? [英] Why is NSPopUpButtonCell showing correctly when only setObjectValue:nil is called?

查看:270
本文介绍了为什么只调用setObjectValue:nil时NSPopUpButtonCell显示正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSTableView 有多个 NSCell s(间接通过 NSTableColumn )。 NSCell遵循Flyweight设计模式;他们是饼干刀。每列有一个单元格,并要求每列绘制自己。 这与基于视图的表格视图(每个单元格都有一个视图实例)相反。

An NSTableView has multiples NSCells (indirectly via NSTableColumn). NSCell follows the Flyweight design pattern; they're cookie-cutters. There's one cell per column and it's asked to draw itself for each row. "Here's a value, draw it on the first row; here's the value for the second row, etc." This is in contrast to view-based tableviews which have a view instance per cell.

我已经对NSPopUpButtonCell进行了子类化,对于每个 setXxxValue:方法,我调用 NSLog / code>并将消息转发到超类。调用的唯一方法(例如,当添加新行或以其他方式刷新表)是 setObjectValue:。这可以通过文档 ...但是 null 是传递给它的唯一的东西!它应该传递一个NSNumber与所选的项目索引。

I've subclassed NSPopUpButtonCell and for each setXxxValue: method, I call NSLog(); and forward the message to the super class. The only method which gets called (say, when adding new rows, or otherwise refreshing the table) is setObjectValue:. This is expected from the documentation... but null is the only thing passed to it!! It should be passed an NSNumber with the selected item index.

我的表很好。我只是试图理解这,扩展/改变单元格的行为(显然我不会需要一个子类)。

My table draws fine. I'm just trying to understand this because I want to extend/change the behaviour of the cell (obviously as I would'nt have needed a subclass otherwise).

问题:可能?如何将NSPopUpButtonCell设置为一个值,以便为每一行绘制正确的值。即使考虑绑定,它的NSTableColumn做重型起重,没有?我缺少什么?

Question: How is this possible? How is the NSPopUpButtonCell being set to a value in order to draw the right value for each row. Even considering bindings, it's NSTableColumn doing the heavy lifting, no? What am I missing?

推荐答案

表中的每一行都共享相同的弹出菜单 - 不需要

"Every row in a table shares the same popup menu" – that doesn't need to be the case.

除了设置表列的值绑定之外,还可以通过数组控制器将单元格的内容绑定设置为模型对象的数组属性。

In addition to setting the table column's value binding, set the cell's content binding to an array property of your model object, via your array controller.

您可以保留确定模型中选项的代码(只需创建一个字符串数组)。这样,你不需要一个自定义子类。

You can keep the code which determines the options in the model (just create an array of strings). That way you won't need a custom subclass.

这篇关于为什么只调用setObjectValue:nil时NSPopUpButtonCell显示正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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