这是一个参考自 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
#import <DataBindingLib/DataBindingLib.h>
@implementation ExampleModel
- (void)dealloc{
[[DataBindingUtil dataBindingUtil] unbindModel:self];
}
@end
KeyPath | Value | 说明
----------------------------------------------------
BindType | ExampleModel | 对应绑定model的名称如:Example Model
BindMethod:string | setText: | BindMethod: 对应监听的Property名称,及当property改变后调用的方法 此处将监听string 这个 property setText:当string改变后,以string的值为参数调用setText:这个方法
_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