CCUIModel
CCUIModel 是一个有用的库,可以使 UI 由模型驱动。
使用方法:具有单模型关系的 UI 属性 *直接设置值: * UI 属性类型是 id:[CCUIModel makeRelation:^(void) { label.text = createNotifer(person, @"name").idValue; }]; * UI 属性类型是 bool:[CCUIModel makeRelation:^(void) { label.hidden = createNotifer(person, @"display").idValue.boolValue; }]; * 需要转换模型值:_label.text = [createNotifer(person, @"name") setTransfer:^id(id value) { return [NSString stringWithFormat:@"name:%@",value]; }].idValue; * 当模型值改变时调用方法或选择符: * 选择符:[createNotifer(person, @"name") makeRelation:self WithSelector:@selector(setText:)]; * 块:[createNotifer(person, @"name") makeRelation:self withBlock:^(id value) { _label.text = value; }]; 有时 UI 属性将关联多个模型值:在这种情况下,我们需要设置一个转换。 * 直接设置值:
CCUIModel* uimodel = createNotifer(person, @"name").with(createNotifer(person, @"age")).with(createNotifer(person, @"title"));
[uimodel setTransfer3:^id(id name, id age, id title) {
return [NSString stringWithFormat:@"name:%@ age:%@ title:%@", name, age, title];
}];
_label.text = uimodel.idValue;
* notify to selector
CCUIModel* uimodel = createNotifer(person, @"name").with(createNotifer(person, @"age")).with(createNotifer(person, @"title"));
[uimodel setTransfer3:^id(id name, id age, id title) {
return [NSString stringWithFormat:@"name:%@ age:%@ title:%@", name, age, title];
}];
[uimodel addBind:self WithSelector:@selector(setText:)];
* notify to block
CCUIModel* uimodel = createNotifer(person, @"name").with(createNotifer(person, @"age")).with(createNotifer(person, @"title"));
[uimodel setTransfer3:^id(id name, id age, id title) {
return [NSString stringWithFormat:@"name:%@ age:%@ title:%@", name, age, title];
}];
[uimodel addBind:self withBlock:^(id value) {
_label.text = value;
}];
I have already init some propery default, If you need to make relation with new ui property, please do as following
bool initListenerProperty(Class cls, NSString* prop);
init listener property
示例
要运行示例项目,首先从 Example 目录克隆仓库,然后运行 pod install
。
需求
安装
CCUIModel 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中
pod "CCUIModel"
作者
aruisi, [email protected]