简体   繁体   English

我是否需要对Image&Text NSTableCellView进行子类化才能添加标签?

[英]Do I need to subclass the Image&Text NSTableCellView to add a label?

I have a view-based NSTableView (using the Image&Text CellView). 我有一个基于视图的NSTableView(使用Image&Text CellView)。

Depending on the dataItems in the dataSource, I select an appropriate CellView to display them. 根据dataSource中的dataItem,我选择一个适当的CellView来显示它们。

One of the templates has an additional (to the default CellView) label on it. 其中一个模板上面带有一个附加标签(默认为CellView)。 But I don't know what is the right way to access it when I instantiate the CellView (I need to set label's value). 但是我不知道在实例化CellView时访问它的正确方法是什么(我需要设置标签的值)。

My question basically is - should I search for the subview (like in the following snippet) or should I subclass the CellView, add a property and so on? 我的问题基本上是-我应该搜索子视图(如下面的代码片段所示)还是子类化CellView,添加属性等等?

    NSArray* subviews = [cellView subviews];
    for (id view in subviews) {
        ViewType* view = (ViewType*)view;
        if ( view != nil ) {
            if ( [view.identifier isEqualToString:@"idSetInIB"] ) {
                [view setStringValue:dataItem.someValue];
            }
        }
    }

Thanks. 谢谢。

The Apple TableView Programming guide gives good basic examples on how to subclass NSTableCellView for a view based table. Apple TableView编程指南提供了很好的基本示例,说明了如何为基于视图的表子类NSTableCellView。

It's probably a little easier to do without bindings. 不使用绑定可能会容易一些。 And certainly better for learning it. 当然更好地学习它。

However, you should be able to just add another text field in Interface Builder to the table cell view. 但是,您应该只需要在Interface Builder中向表单元格视图添加另一个文本字段即可。

Read the guide. 阅读指南。 It will help tremendously. 这将极大地帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM