gpt4 book ai didi

objective-c - 将行 NSRuleEditor 与数组绑定(bind)

转载 作者:太空狗 更新时间:2023-10-30 03:33:51 27 4
gpt4 key购买 nike

在开发者文档中我发现了这个:

NSRuleEditor exposes one binding, rows. You can bind rows to an ordered collection (such as an instance of NSMutableArray). Each object in the collection should have the following properties:

  • @"rowType" An integer representing the type of the row(NSRuleEditorRowType).

  • @"subrows" An ordered to-many relation (such as an instance of NSMutableArray) containing the directly nested subrows for the given row.

  • @"displayValues" An ordered to-many relation containing the display values for the row.

  • @"criteria" An ordered to-many relation containing the criteria for the row.

有人可以举例说明如何做到这一点吗?

最佳答案

=========== 编辑 =============

根据我的研究,NSRuleEditor 类 header 包含下一个关于绑定(bind)的文档:

* -- Bindings support -- */

/* Sets the class used when creating a new row in the "rows" binding; this class should be KVC and KVO compliant for the key paths listed below. By default this is NSMutableDictionary */
- (void)setRowClass:(Class)rowClass;
- (Class)rowClass;

/* Set and get the key path for the row type, which is used to get the row type in the "rows" binding. The row type is a value property of type NSRuleEditorRowType. The default is @"rowType". */
- (void)setRowTypeKeyPath:(NSString *)keyPath;
- (NSString *)rowTypeKeyPath;

/* Set and get the key path for the subrows, which is used to determined nested rows in the "rows" binding. The subrows property is an ordered to-many relationship containing additional bound row objects. The default is @"subrows". */
- (void)setSubrowsKeyPath:(NSString *)keyPath;
- (NSString *)subrowsKeyPath;

/* Set and get the criteria key path, which determines the criteria for a row in the "rows" binding. (The criteria objects are what the delegate returns from - ruleEditor: child: forCriterion: withRowType:). The criteria property is an ordered to-many relationship. The default is @"criteria". */
- (void)setCriteriaKeyPath:(NSString *)keyPath;
- (NSString *)criteriaKeyPath;

/* Set and get the display values key path, which determines the display values for a row (the display values are what the delegate returns from - ruleEditor: displayValueForCriterion: inRow:). The criteria property is an ordered to-many relationship. The default is @"displayValues". */
- (void)setDisplayValuesKeyPath:(NSString *)keyPath;
- (NSString *)displayValuesKeyPath;

为了扩展答案,我将给出下一个示例,以便您了解如何将自己的类绑定(bind)为行:

@interface BindObject : NSObject

@property (nonatomic, assign) NSInteger rowType;
@property (nonatomic, strong) NSMutableArray *subrows;
@property (nonatomic, strong) NSMutableArray *displayValues;
@property (nonatomic, strong) NSMutableArray *criteria;

@end

// binding custom class as row class
[self.ruleEditor setRowClass:[BindObject class]];

现在,当您向 NSRuleEditor 添加新行时,您的类将被使用。您还可以更改 KeyPath,这样自定义行类中的字段(ivars/属性)的调用方式可能与文档中指定的不同。

希望这能帮助您理解 NSRuleEditor 的工作原理。

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

我找到了 this article ,它应该可以帮助您了解 NSRuleEditor 的工作原理。

关于objective-c - 将行 NSRuleEditor 与数组绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9081976/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com