Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios ReactiveCocoa-如何使用';切换到最新的';?_Ios_Objective C_Reactive Cocoa - Fatal编程技术网

Ios ReactiveCocoa-如何使用';切换到最新的';?

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]; 我看到的问题是,细胞永远不会在

我有一个具有viewModel属性的UITableViewCell。随着tableview单元的重用,我希望它绑定到其最新viewModel的属性,如下所示:

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);
}