-(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);
//當(dāng)bindV.bageCount變化的時候,btn.count也是隨著變化节吮。
}
@implementation HYMBtn
- (void)setBindView:(bindView *)bindView {
//將自身.count屬性綁定到bindView.bageCount屬性上指黎,當(dāng)bageCount發(fā)生變化的時候鸟廓,自身.count屬性也隨著變化
[self bind:@"count" toObject:bindView withKeyPath:@"bageCount" options:nil];
}
//解除綁定
-(void)dealloc {
[self unbind:@"count"];
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者