美文网首页iOSRAC实战
ReactiveCocoa在UITableViewCell复用的

ReactiveCocoa在UITableViewCell复用的

作者: 踏云小子 | 来源:发表于2017-04-14 14:54 被阅读26次

1.cell的复用

之前遇到一个蛋疼问题,就是cell中又按钮,当订阅按钮点击事件时候,结果因为cell的复用,出现多个按钮事件

[[cell.playBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        
    }];

so,解决方案有两种

  • 方案一:UITableViewCell复用时需要取消cell上各个组件的订阅
- (void)prepareForReuse {
    [super prepareForReuse];
    [self.playBtn dispose], self.playBtn = nil;
}
  • 方案二:使用rac_prepareForReuseSignal
[[[cell.playBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:cell.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        
    }];

相关文章

网友评论

    本文标题:ReactiveCocoa在UITableViewCell复用的

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