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
190
Test With Xcode Server
wpsteak
0
64
Other Decks in Programming
See All in Programming
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
CSC509 Lecture 13
javiergs
PRO
0
110
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
距離関数を極める! / SESSIONS 2024
gam0022
0
280
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
How GitHub (no longer) Works
holman
310
140k
Visualization
eitanlees
145
15k
Speed Design
sergeychernyshev
25
620
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Building an army of robots
kneath
302
43k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
What's new in Ruby 2.0
geeforr
343
31k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
890
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