Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
a lighter reusable cell
Search
Pin-Shih Wang
October 01, 2012
Programming
0
53
a lighter reusable cell
for TableView & CollectionView
https://github.com/wpsteak/MVCTableViewExample
Pin-Shih Wang
October 01, 2012
Tweet
Share
More Decks by Pin-Shih Wang
See All by Pin-Shih Wang
iOS Extension
wpsteak
4
450
A tip for using magical record
wpsteak
0
110
CI with Git Flow
wpsteak
2
200
Test With Xcode Server
wpsteak
0
64
Other Decks in Programming
See All in Programming
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
640
情報漏洩させないための設計
kubotak
3
600
Go の GC の不得意な部分を克服したい
taiyow
3
820
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
320
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
330
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
500
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
500
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
280
Zoneless Testing
rainerhahnekamp
0
120
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
170
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Docker and Python
trallard
42
3.1k
Building an army of robots
kneath
302
44k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Designing for humans not robots
tammielis
250
25k
The Cost Of JavaScript in 2023
addyosmani
46
7k
Faster Mobile Websites
deanohume
305
30k
For a Future-Friendly Web
brad_frost
175
9.4k
Transcript
a lighter reusable cell for TableView & CollectionView @wpsteak
None
TableView
ViewController TableView
ViewController TableView DataSource
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells? TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells? 1000 Cells? TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells? 1000 Cells? Add/remove subview every time? TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells? 1000 Cells? Add/remove subview every time? TableCell
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get Cell
Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells? 1000 Cells? Add/remove subview every time? TableCell <reuse>
Step1 move logic into cell
None
TableView
ViewController TableView
ViewController TableView DataSource
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells?
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells?
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells? 1000 Cells?
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells? 1000 Cells? Add/remove subview every time?
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells? 1000 Cells? Add/remove subview every time? <reuse>
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells? 1000 Cells? <reuse>
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon return Cell 10 Cells? 100 Cells? 1000 Cells? <reuse> prepareForReuse
Step2 split logics
TableViewCell / CollectionViewCell • Init UI • PrepareForReuse (reset UI)
• SetupContent with DataModel (set data)
None
Controller
Model Controller
Model Controller PrepareDataList Model Model Model
TableCell Model Controller PrepareDataList Model Model Model
TableCell Model Controller PrepareDataList Model Model Model SetupContent Model Update
UI
TableCell Model Controller PrepareDataList Model Model Model prepare data handle
user interaction data display SetupContent Model Update UI
- (void)initControl { init UI… } - (void)setupContent:(id)data { update
UI with new content } - (void)prepareForReuse { [super prepareForReuse]; reset UI reset logic } Sample
None
TableView
ViewController TableView
ViewController TableView DataSource
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource
ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell (init Control at first time) Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell (init Control at first time) Create UILabel1 Create UILabel2 Create Image1 Create Image2 Create Icon set Data
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell prepareForReuse setup Content update UI set Data
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell return Cell prepareForReuse setup Content update UI set Data
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell return Cell prepareForReuse setup Content update UI set Data
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell return Cell 10 Cells prepareForReuse setup Content update UI set Data
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell return Cell 10 Cells 100 Cells prepareForReuse setup Content update UI set Data
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell return Cell 10 Cells 100 Cells 1000 Cells prepareForReuse setup Content update UI set Data
TableCell ViewController - (UITableViewCell *) tableView: cellForRowAtIndexPath: TableView DataSource Get
Cell return Cell 10 Cells 100 Cells 1000 Cells <reuse> prepareForReuse setup Content update UI set Data
• init UIView once and only once • reset UI
and necessary logic in prepareForReuse: method
End