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(内边距/ ...
随机推荐
- web.py 学习(二)Worker
Rocket Server 启动一个线程监听客户端的连接,收到连接将连接放置到队列中.线程池中的Worker会以这个连接进行初始化.Rocket中Worker的基类是: class Worker(Th ...
- CevaEclipse - 编译器attribute扩展
1.函数与变量的 Section Attribute void foobar (void) __attribute__ ((section (".CSECT mmm"))); vo ...
- Openjudge-计算概论(A)-称体重
描述: 赵.钱.孙.李四个人中既有大人也有小孩,给他们称体重时发现,他们每个人的体重都不一样,且体重(单位:公斤)恰好是10的整数倍,且他们的体重都不高 于50公斤,已知赵.钱两人的体重之和恰好等于孙 ...
- 【TestDirector】常见问题分析
1.IE7无法访问TD 问题原因:兼容性问题 解决方法:步骤一.以系统管理员身份登陆TD: 步骤二.找到TD服务器中TDBIN目录(缺省情况下是C:\Inetpub\TDBIN目录),用编辑器打开st ...
- iOS 计算两个坐标之间的距离
//第一个坐标 CLLocation *before=[[CLLocation alloc] initWithLatitude:29.553968 longitude:106.538872]; //第 ...
- MVC view视图获取Html.RenderAction方式带来的参数
通过Html.RenderAction这种方式传递的参数,在view视图中获取要使用viewContext上下文来获取:Html.ViewContext.RouteData.Values[" ...
- Shell脚本常用判断
-e filename 如果 filename存在,则为真 -d filename 如果 filename为目录,则为真 -f filename 如果 filename为常规文件,则为真 -L fi ...
- IntelliJ Idea 常用快捷键列表(转)
IntelliJ Idea 常用快捷键列表 Alt+回车 导入包,自动修正Ctrl+N 查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L 格式化代码 Ctrl+Alt+O 优化导 ...
- html5学习(二)音频audio
音频格式 当前,audio 元素支持三种音频格式: IE 9 Firefox 3.5 Opera 10.5 Chrome 3.0 Safari 3.0 Ogg Vorbis √ √ √ M ...
- Sublime Text: [Decode error - output not utf-8]
今天编译Python时, 输出窗口信息出现: [Decode error - output not utf-8][Decode error - output not utf-8] 发现是print ...