2

我正在尝试配置一个NSPredicateEditor(在 Interface Builder 中)来编辑一个NSMetadataQuery.

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

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

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

NSPopUpButton我不知道在 IB 中导航到哪里可以找到NSExpression.

任何帮助表示赞赏。

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

4

1 回答 1

1

我发现NSPredicateEditor在 Interface Builder 中与朋友一起工作是一项非常乏味的任务。出于这个原因,我在代码中完成了所有行模板配置。

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

#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本地化选项来显示不同的名称。

于 2011-01-17T01:08:28.980 回答