美文网首页
bind:(NSString *)binding toObjec

bind:(NSString *)binding toObjec

作者: min369 | 来源:发表于2017-09-02 19:11 被阅读20次
-(void)bind:(NSString *)binding toObject:(id)observableController withKeyPath:(NSString *)keyPath options:(NSDictionary *)options
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    bindV = [[bindView alloc] init];
    btn = [[HYMBtn alloc] init];
    bindV.bageCount = 0;
    [btn setBindView:bindV];
}
- (IBAction)btnClick:(id)sender {
    bindV.bageCount ++;
    NSLog(@"=====%d",bindV.bageCount);
    NSLog(@"+++++++%d",btn.count);
//当bindV.bageCount变化的时候,btn.count也是随着变化。
}
@implementation HYMBtn
- (void)setBindView:(bindView *)bindView {
//将自身.count属性绑定到bindView.bageCount属性上,当bageCount发生变化的时候,自身.count属性也随着变化
    [self bind:@"count" toObject:bindView withKeyPath:@"bageCount" options:nil];
}

//解除绑定
-(void)dealloc {
    [self unbind:@"count"];
}

相关文章

网友评论

      本文标题:bind:(NSString *)binding toObjec

      本文链接:https://www.haomeiwen.com/subject/cyprjxtx.html