【问题标题】:Configuring NSPredicateEditor(RowTemplate) for Spotlight metadata queriesI'为 Spotlight 元数据查询配置 NSPredicateEditor(RowTemplate)I'
【发布时间】:2011-06-10 03:28:33
【问题描述】:

我正在尝试配置 NSPredicateEditor(在 Interface Builder 中)来编辑 NSMetadataQuery 的谓词。

作为第一步,我尝试配置 NSPredicateEditorRowTemplate 以接受左侧表达式的键路径,尝试使用单个 keyPath (kMDItemTextContent) 开始。

我不知道如何将所有部分都放入 IB。我选择了行模板,并在 IB Attributes Inspector 中将“Left Exprs”设置为“Key Paths”。但是,使用 Apple 的 PhotoSearch 示例作为模型,我似乎应该在此处输入用户可读的属性名称(例如“内容”);我不知道如何将其绑定到“kMDItemTextContent”。

我在 PhotoSearch(*) 中剖析了(正确配置的)NIB,其中有一个 NSKeyPathExpression 指定附加到 NSPopUpButton/NSPopUpButtonCell 的元数据属性。

我不知道在 IB 中的哪个位置可以找到 NSPopUpButton,而且我不确定如何将其绑定到 NSExpression

任何帮助表示赞赏。

(*) 如果您想知道,我通过将其转换为 XIB 进入了 NIB,确认它仍然可以正确构建,然后使用 BBEdit 检查它。

【问题讨论】:

    标签: cocoa spotlight nspredicateeditor


    【解决方案1】:

    我发现在 Interface Builder 中与NSPredicateEditor 和朋友一起工作是一项极其乏味的任务。因此,我在代码中完成所有行模板配置。

    对于您的情况,听起来您不需要自定义行模板子类,因此您可以这样做:

    #define NSPERT NSPredicateEditorRowTemplate
    NSPERT * template = [[NSPERT alloc] initWithLeftExpressions:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:kMDItemTextContent]] 
                                   rightExpressionAttributeType:NSStringAttributeType
                                                       modifier:NSDirectPredicateModifier
                                                      operators:[NSArray arrayWithObject:
                                                                 [NSNumber numberWithUnsignedInteger:NSContainsPredicateOperatorType]]
                                                        options:(NSCaseInsensitivePredicateOption|NSDiacriticInsensitivePredicateOption)];
    

    获得模板后,只需将其添加到 predicateEditor:

    NSMutableArray * templates = [[myPredicateEditor rowTemplates] mutableCopy];
    [templates addObject:template];
    [template release];
    [myPredicateEditor setRowTemplates:templates];
    [templates release];
    

    至于翻译“kMDItemTextContent”,如果它不会自动发生(我认为它可能会发生),您可以使用NSPredicateEditor localization options 显示不同的名称。

    【讨论】:

    • 快速回答,谢谢!我已经启动并运行了;唯一的问题是在将它们添加到输入数组之前,必须将键路径包装在 [NSExpression expressionForKeyPath:keyPath] 中。
    • @Doug 哦,对了,很好。这就是我在浏览器中输入的结果。
    猜你喜欢
    • 2014-02-14
    • 2010-11-04
    • 2010-09-17
    • 1970-01-01
    • 2017-03-08
    • 2010-10-23
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    相关资源
    最近更新 更多