基于视图的NSOutlineView标题单元格字体问题 [英] View-based NSOutlineView header cell font issues

查看:249
本文介绍了基于视图的NSOutlineView标题单元格字体问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正试图在我的Cocoa应用程序中使用一个新的基于视图的NSOutlineView。由于我不使用绑定,所以我实现了所有需要的委托和数据源方法在我的控制器。

I'm currently trying to use a new view-based NSOutlineView in my Cocoa app. As I'm not using bindings, so I implemented all required delegate and datasource methods in my controller.

在界面构建器中,我添加了一个NSOutlineView,其突出显示设置为 SourceList ,内容模式设置为 View Based 。因此,提供了两个默认表格单元视图(一个具有设置为标识符的头部单元 HeaderCell 和设置为标识符的 DataCell 的一个数据单元)

In interface builder I've added a NSOutlineView with a highlighting set to SourceList and Content Mode set to View Based. Thus, there were two default table cell views provided (one Header cell with HeaderCell set as identifier and one data cell with DataCell set as identifier)

这是在界面构建器中,标题单元格视图正确显示灰色蓝色的 textField ,而数据单元格视图有一个图像视图和一个 textField 正确的颜色和字体设置

This is what it looks like in interface builder, header cell views correctly show a grey-blue textField while data cell views have a image view and a textField with correct color and font settings

为了提供视图,我使用以下代码,返回一个DataCell视图或一个HeaderCell视图,并相应地基于在接口构建器中设置的相应标识符设置单元格的textField。

To provide the views, I use the following code, to return a DataCell-view or a HeaderCell-view and set the textField of the cell accordingly, based on the corresponding identifier set in interface builder.

- (NSView *)outlineView:(NSOutlineView *)outlineView 
     viewForTableColumn:(NSTableColumn *)tableColumn 
                   item:(id)item {


    NSTableCellView *result = nil;

    if ([item isKindOfClass:[NSMutableDictionary class]]) {
        result = [outlineView makeViewWithIdentifier:@"HeaderCell" owner:self];

        id parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : groupedRoster;
        [[result textField] setStringValue:[[parentObject allKeys] objectAtIndex:0]];


    } else {
        result = [outlineView makeViewWithIdentifier:@"DataCell" owner:self];

        [item nickname] ? [[result textField] setStringValue:[item nickname]] : [[result textField] setStringValue:[[item jid] bare]];
    }
    return result;
}

运行它看起来像下面的一切。

Running everything it looks like the following.

任何人都可以提供

推荐答案

您需要实现-outlineView :isGroupItem:delegate方法,并为您的标题行返回YES。这将标准化字体,并用左侧的显示/隐藏按钮替换左侧的公开三角形。您仍然需要手动将字符串大写以获得完整的效果。

You need to implement the -outlineView:isGroupItem: delegate method and return YES for your header rows. That will standardize the font and replace the disclosure triangle on the left with a Show/Hide button on the right. You will still need to manually uppercase your string to get the full effect.

我不确定上面的组行委托方法是否使选择样式看起来不错。但是,通常不希望在源列表中可以选择标题行,您可以通过对-outlineView:shouldSelectItem:delegate方法的标题项返回NO。

I'm not sure if the group row delegate method above makes the selection style look okay or not. However, you normally don't want the header rows to be selectable at all in source lists, which you by returning NO for header items from the -outlineView:shouldSelectItem: delegate method.

这篇关于基于视图的NSOutlineView标题单元格字体问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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