cell reuse & disposebag
For my project I've made base cell
class TableViewCell: UITableViewCell {
private(set) var disposeBag = DisposeBag()
override func prepareForReuse() {
super.prepareForReuse()
disposeBag = DisposeBag() // because life cicle of every cell ends on prepare for reuse
}
}
and now in your cell factory you should do:
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! DiaryItemCell
cell.commentButton.rx_tap
.subscribeNext{
showAlert("Hi")
}.addDisposableTo(cell.disposeBag)
return cell
All disposables (CompositeDisposable, SerialDisposable, AnonymousDisposable ...) have the same behavior.
- once they are disposed, adding another disposable with
addDisposablewill calldisposeimmediately (@sergdot that's whyself.compositeDisposable.dispose()was causing that weird behavior ;) - they don't call dispose automatically on deinit
All classes named *Disposable are meant to be used while implementing your own Rx operators.
DisposeBag is meant to return ARC like memory management to subscriptions, and it will dispose all subscriptions (Disposables) it contains on deinit.
Hope this clears things up :)
cell reuse & disposebag的更多相关文章
- How To Make A Swipeable Table View Cell With Actions – Without Going Nuts With Scroll Views
How To Make A Swipeable Table View Cell With Actions – Without Going Nuts With Scroll Views Ellen S ...
- 关于使用uitableview 中cell 来实现uiimageview的复用和图片的异步加载
apple sample lazytableimages 1,首先设置横向显示的uitableview self.customTableview.transform = CGAffineTransfo ...
- socket网络间通信初识
NSOperation: 1. 指定同一时间最大执行的操作数 queue.max…… 2. 设定队列中的任务时间的依赖关系 task1 依赖于 task2: task2 —> task1 3. ...
- iphone Dev 开发实例9:Create Grid Layout Using UICollectionView in iOS 6
In this tutorial, we will build a simple app to display a collection of recipe photos in grid layout ...
- 二、UITableView和它的亲戚们
. UITableView 参考: https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableView ...
- [翻译] Haneke(处理图片缓存问题)
Haneke https://github.com/hpique/Haneke A lightweight zero-config image cache for iOS. 轻量级0配置图片缓存. H ...
- [翻译] SWTableViewCell
SWTableViewCell An easy-to-use UITableViewCell subclass that implements a swippable content view whi ...
- UITableView使用指南
本文转载至 http://blog.csdn.net/yu0089/article/details/8227402 一.概述 UITableView是iOS开发比不可少也是最重要的一个控件类.可以说任 ...
- ios 布局 素材 待整理
https://www.cnblogs.com/fxwl/p/5961372.html div区域 8.盒子模型的相关属性 margin(外边距/边界) border(边框) padding(内边距/ ...
随机推荐
- openwrt的uboot环境变量分析
目前烧写完CC(chaos calmer 15.05)版本,查看其uboot变量如下: ath> printenvbootargs=console=ttyS0,115200 root=31:02 ...
- OpenGL多视口
#include <gl/glew.h> #include <gl/freeglut.h> #include <iostream> ; ; float rtri = ...
- 站在Java的角度看LinkedList
站在Java的角度看,玩队列不就是玩对象引用对象嘛! public class LinkedList<E> implements List<E>, Deque<E> ...
- 抛弃阿里云,中国用户购买海外VPS的五个理由
王掌柜在过去的五年多时间里,折腾过不少vps品牌,最开始玩的是一年一百多块钱的香港虚拟主机,后来业务量大了,开始折腾国内的小鸟云.阿里云.腾讯云.电信云.百度云主机,国外的linode\interse ...
- CEdit实现文本换行
CEdit控件若要在字符串中插入换行字符("\r\n")实现换行效果,必须指定两个风格 ES_MULTILINE和ES_WANTRETURN. 1: DWORD dwStyle = ...
- amazeui 搜索 动态
<!doctype html> <html class="no-js"> <head> <meta charset="utf-8 ...
- Openjudge-计算概论(A)-判断闰年
描述: 判断某年是否是闰年.输入输入只有一行,包含一个整数a(0 < a < 3000)输出一行,如果公元a年是闰年输出Y,否则输出N样例输入 2006 样例输出 N 提示:公历纪年法中, ...
- Android应用测试性能的工具Emmagee,导出文件格式问题分析
原文引用自:http://www.open-open.com/lib/view/open1367026451078.html Emmagee是监控指定被测应用在使用过程中占用机器的CPU.内存.流量资 ...
- Smarty 注册变量
关于smarty类的一些解析 特别注意左右分隔符<{}>,display------显示模板的内容(里面是.html文件),assign-------注册变量 <?php //是一个 ...
- 移动端touch事件影响click事件的相关解决方法
preventDefault()的方法,阻止事件的默认行为. 在移动端,手指点击一个元素,会经过:touchstart --> touchmove -> touchend -->cl ...