我正在尝试获得一个NSRuleEditor
显示标准。如果我给它一个单一的标准,它会起作用(创建一个静态标签),但是当我给它一个以上的时候,规则编辑器的每一行都是空白的(除了添加/删除按钮之外没有添加子视图)。为什么会这样?我的代码如下。
struct RuleItem {
var text: String
var children: [RuleItem] = []
}
var ruleItems = [
RuleItem(text: "hello"),
RuleItem(text: "world", children: [
RuleItem(text: "child 1"),
RuleItem(text: "child 2")
])
]
// In class conforming to NSRuleEditorDelegate:
func ruleEditor(_ editor: NSRuleEditor, numberOfChildrenForCriterion criterion: Any?, with rowType: NSRuleEditor.RowType) -> Int {
if let item = criterion as AnyObject as? RuleItem {
return item.children.count
} else {
return ruleItems.count
}
}
func ruleEditor(_ editor: NSRuleEditor, child index: Int, forCriterion criterion: Any?, with rowType: NSRuleEditor.RowType) -> Any {
if let item = criterion as AnyObject as? RuleItem {
return item.children[index]
} else {
return ruleItems[index]
}
}
func ruleEditor(_ editor: NSRuleEditor, displayValueForCriterion criterion: Any, inRow row: Int) -> Any {
(criterion as AnyObject as! RuleItem).text as NSString
}