Ios ReactiveCocoa-如何使用';切换到最新的';?
我有一个具有viewModel属性的UITableViewCell。随着tableview单元的重用,我希望它绑定到其最新viewModel的属性,如下所示:Ios ReactiveCocoa-如何使用';切换到最新的';?,ios,objective-c,reactive-cocoa,Ios,Objective C,Reactive Cocoa,我有一个具有viewModel属性的UITableViewCell。随着tableview单元的重用,我希望它绑定到其最新viewModel的属性,如下所示: RAC(self.titleLabel, text) = [[RACObserve(self, viewModel) map:^id(MyViewModel *viewModel) { return RACObserve(viewModel, title); }] switchToLatest]; 我看到的问题是,细胞永远不会在
RAC(self.titleLabel, text) =
[[RACObserve(self, viewModel) map:^id(MyViewModel *viewModel) {
return RACObserve(viewModel, title);
}]
switchToLatest];
我看到的问题是,细胞永远不会在应该释放的时候释放。
有没有办法在释放电池时处理信号?我错了
RACObserve()
将保留self–我缺少一个@strongify(self)
。
解决方法:
@weakify(self);
RAC(self.titleLabel, text) =
[[RACObserve(self, viewModel) map:^id(MyViewModel *viewModel) {
@strongify(self);
return RACObserve(viewModel, title);
}]
switchToLatest];
让我补充一点,有一种更简洁的写作方式。假设您正在为单元格使用故事板或XIB:
- (void)awakeFromNib {
[super awakeFromNib];
RAC(self, textLabel.text) = RACObserve(self, viewModel.title);
}