DataBindingLib 1.0.2

DataBindingLib 1.0.2

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2016年8月

Halin 维护。



  • 作者
  • Halin

这是一个参考自 Android DataBinding (https://developer.android.com.cn/tools/data-binding/guide.html) 的库,其用法与 Android 的 DataBinding 非常相似,通过 xib 的 User Defined Runtime Attributes 实现对 model 的绑定(类似于 Android xml 的 binding),设置绑定模型与绑定方法,

This is a lib base on 'Android DataBinding' (https://developer.android.com.cn/tools/data-binding/guide.html) , It use like Android DataBinding , You can bind model and method through 'User Defined Runtime Attributes'

原谅我糟糕的英语,没有英文文档和注释,但如果您对此感兴趣,请给我发邮件,我会告诉您如何使用及其工作方式。同时也希望您能帮助我编写英文文档和注释... 我的电子邮件地址:[email protected]

使用方法

要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install

1. 添加模型,并在模型的 dealloc 方法中调用 DataBindingUtil 的 unbindModel: 方法

#import <DataBindingLib/DataBindingLib.h>
@implementation ExampleModel

- (void)dealloc{
[[DataBindingUtil dataBindingUtil] unbindModel:self];
}

@end

2. 在 User Defined Runtime Attributes 添加对应的 model 类型(类名),已经监听的 property 及当监听改变时调用的方法

KeyPath            |         Value       |    说明
----------------------------------------------------
BindType           |      ExampleModel   |    对应绑定model的名称如:Example Model        
BindMethod:string  |      setText:       |    BindMethod: 对应监听的Property名称,及当property改变后调用的方法 此处将监听string 这个 property  setText:当string改变后,以string的值为参数调用setText:这个方法

3. 实现绑定,构造一个 model 并调用 bindModel: 绑定模型 model 相当于 Android DataBinding 的 Binding

_exampleModel = [[ExampleModel alloc] init];
[[DataBindingUtil dataBindingUtil] bindModel:_exampleModel forView:self.view];

_exampleModel.string = @"Test Start";

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
_exampleModel.string = @"String has been changer by binder";
});

要求

安装

DataBindingLib 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod "DataBindingLib"

作者

Halin, [email protected]

许可证

DataBindingLib 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。-Warc-performSelector-leaks