Связать строки NSRuleEditor с массивом - PullRequest
8 голосов
/ 31 января 2012

В документации разработчика я нашел это:

NSRuleEditor выставляет одну привязку, rows.Вы можете привязать rows к упорядоченной коллекции (например, к экземпляру NSMutableArray).Каждый объект в коллекции должен иметь следующие свойства:

  • @ "rowType" Целое число, представляющее тип строки (NSRuleEditorRowType).

  • @ "subrows" Упорядоченное отношение ко-многим (например, экземпляр NSMutableArray), содержащее вложенные вложенные подстроки для данной строки.

  • @ "displayValues" Упорядоченное ко-многимотношение, содержащее отображаемые значения для строки.

  • @ "критерии" Упорядоченное отношение ко многим, содержащее критерии для строки.

Кто-нибудь может привести пример, как это сделать?

1 Ответ

2 голосов
/ 17 апреля 2013

=========== РЕДАКТИРОВАТЬ =============

Как я исследовал, заголовок класса NSRuleEditor содержит следующую документацию по связыванию:

* -- 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;

И чтобы расширить ответ, я приведу следующий пример, чтобы вы поняли, как связать свой собственный класс в виде строк:

@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 / properties) в вашем пользовательском классе строк могли вызываться не так, как указано в документации.

Надеюсь, это поможет вам понять, как работает NSRuleEditor.

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

Я нашел эту статью ,это должно помочь вам понять, как работает NSRuleEditor.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...