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(内边距/ ...
随机推荐
- java.net.NoRouteToHostException: No route to host
报错信息: java.net.NoRouteToHostException: No route to host at java.net.PlainSocketImpl.socketCon ...
- LeetCode OJ 85. Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and ...
- LeetCode OJ 31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- MC- 交易并设置止损
using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; using ATCenterP ...
- HDtune(硬盘检测) V5.5 中文绿色版
软件名称:HDtune(硬盘检测) V5.5 中文绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win 32位/64位软件大小: 565KB 图片预览: 软件简介:HD Tune Pro一 ...
- G - 娜娜梦游仙境系列——梦醒
G - 娜娜梦游仙境系列——梦醒 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) ...
- 背包问题matlab程序
clearclca=0.95k=[5;10;13;4;3;11;13;10;8;16;7;4];k=-k;d=[2;5;18;3;2;5;10;4;11;7;14;6];restriction=46; ...
- json处理三部曲之第三曲:利用Gson处理json
需要导入gson-xxx.jar包 <dependency> <groupId>com.google.code.gson</groupId> <artifac ...
- Swift Runtime动态性分析
Swift是苹果2014年发布的编程开发语言,可与Objective-C共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序.Swift已经开源,目前最新版本为2.2.我们知道Objec ...
- C# 鼠标事件弹框
if (e.Button == MouseButtons.Right) { if (gridView1.GetFocusedRowCellValue("color").ToStri ...