使用绑定设置 NSBrowserCell 图像?

发布于 2024-07-10 12:13:49 字数 119 浏览 5 评论 0原文

我有一个 NSBrowser 连接到一个绑定到 NSTreeNode 对象数组的 NSTreeController 。 通过设置内容和内容值绑定来正确引用树控制器,让文本部分工作很容易,但如何使用绑定为每个单元格设置图像?

I've got an NSBrowser hooked up to an NSTreeController bound to an array of NSTreeNode objects. It's easy enough to get the text portion working by setting the Content and Content Value bindings to properly reference the tree controller, but how do I set the image for each cell using bindings?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眸中客 2024-07-17 12:13:49

没有内置机制可以仅使用绑定在浏览器单元格中显示图像。 如果你真的想要的话,你可以装配这样的系统,但根据我的经验,有时,为了让你可以说你的所有东西都使用绑定,而跳过障碍更麻烦,而不是值得,而且用老式的方式做事更容易。

将图像放入浏览器单元格的“传统”方法是实现浏览器委托方法:

- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell atRow:(NSInteger)row column:( NSInteger)column

这允许您在浏览器绘制单元格之前自定义单元格。 查看 /Developer/Examples/AppKit 中的 SimpleBrowser 示例,您将在那里找到如何使用此委托方法的示例。 不过,您不应该需要他们在该项目中使用的自定义单元 - 该项目可以追溯到 10.2 年前,即 NSBrowserCell 提供自己的图像绘制机制之前。

There is no built-in mechanism for displaying an image in a browser cell using only bindings. You can rig such a system if you really want, but in my experience, sometimes it's more trouble than it's worth to jump through hoops just so you can say all your stuff uses bindings, and it's just easier to do things the old fashioned way.

The "traditional" method for putting an image in a browser cell is to implement the browser delegate method:

- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell atRow:(NSInteger)row column:(NSInteger)column

This lets you customize the cell however you'd like before it gets drawn by the browser. Take a look at the SimpleBrowser example in /Developer/Examples/AppKit, and you'll find an example of how to use this delegate method there. You shouldn't need the custom cell that they use in that project though - the project hails back from the pre 10.2 days, before NSBrowserCell provided its own image drawing mechanism.

所谓喜欢 2024-07-17 12:13:49

不幸的是,您无法使用 NSBrowserCell 轻松做到这一点。 使用另一个单元格作为浏览器列,该单元格采用 -setObjectValue: 中传递给它的对象值,并适当地填充其自己的文本和图像。

Unfortunately, you can’t easily do this with an NSBrowserCell. Use another cell for your browser columns, one which takes the object value passed to it in -setObjectValue: and populates its own text and image appropriately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文