SlideShare a Scribd company logo
1 of 21
Download to read offline
Unit 4—Lesson 5:
Table Views
Table views
An instance of the UITableView class

A subclass of UIScrollView

• Displays a list of items

• Displays one or possibly thousands of data objects

• Presents vertical scrolling and single-column, multiple rows

• Provides customizable options
Types
Table views
Dynamic Static
When content changes When content doesn’t changes
Table view controllers
Anatomy of a table view
Two possible approaches to add table views:

• Add a table view instance directly to a view
controller’s view 

• Add a table view controller to your
storyboard
Table view styles
Anatomy of a table view
Plain Grouped
Table view cells (UITableViewCell)
Anatomy of a table view
tableView(_:accessoryButtonTappedForRowWith:)
Every row is represented with a table view cell
In editing mode, the cell content shrinks
Cell content Accessory view
Cell content Reordering controlEditing control
UITableViewCell properties
Anatomy of a table view
Cell property Description
textLabel UILabel for the title
detailTextLabel UILabel for the subtitle
imageView UIImageView for an image
UITableViewCell class defines three properties for cell content
UITableViewCellStyle
Anatomy of a table view
Storyboard name Programmatic enum name Displays
Basic .default textLabel, imageView
Subtitle .subtitle textlabel , detailTextLabel, imageView
Right detail .value1 textlabel , detailTextLabel, imageView
Left detail .value2 textLabel , detailTextLabel
Table view readability margins
Anatomy of a table view
Set tableView.cellLayoutMarginsFollowReadableWidth to true
AdjustedDefault
Index paths
Points to a specific row in a specific section

Accessible through the row and section properties 

• indexPath.row

• indexPath.section

Values are zero-based
Arrays and table views
Collection of similar data

Typically backed by a collection of model objects

var emojis: [Emoji]
[Emoji(symbol: Character("😀"), name: "Grinning Face", description: "A typical smiley face.",
usage: "happiness"),
Emoji(symbol: Character("😕"), name: "Confused Face", description: "A confused, puzzled face.",
usage: "unsure what to think; displeasure"),
Emoji(symbol: Character("😍"), name: "Heart Eyes", description: "A smiley face with hearts for
eyes.", usage: "love of something; attractive")]
Cell dequeueing
Arrays and table views
Table views only load visible cells

Saves memory

Allows for a smooth flow when scrolling 

let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for:
indexPath)
Table view protocols
Protocol Description
UITableViewDataSource Provides data for populating sections and rows
UITableViewDelegate (optional) Customizes appearance and behavior
Number of sections
Table view data source (UITableViewDataSource)
optional func numberOfSections(in tableView: UITableView)
-> Int
If function isn’t provided, the table view assumes
one section
Number of rows in a section
Table view data source (UITableViewDataSource)
func tableView(_ tableView: UITableView,

numberOfRowsInSection section: Int) -> Int
Cell for row at index path
Table view data source (UITableViewDataSource)
func tableView(_ tableView: UITableView, 

cellForRowAt indexPath: IndexPath) -> UITableViewCell
Optional
Table view delegate (UITableViewDelegate)
Responding to accessory view interaction

tableView(_:accessoryButtonTappedForRowWith:)
Responding to user interaction

tableView(_:didSelectRowAt:)
Reload data
reloadData()
To force a data refresh
Table Views
Unit 4—Lesson 5
Learn how to create dynamic table views by
creating an emoji dictionary app
Lab: Meal Tracker
Unit 4—Lesson 5
Practice with the UITableViewDataSource and UITableViewController by
creating an app that will display a list of foods, grouped into three sections, one for
each meal of the day
© 2017 Apple Inc. 

This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.

More Related Content

What's hot

Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)Stephen Hay
 
Android resource
Android resourceAndroid resource
Android resourceKrazy Koder
 
Asp.net html server control
Asp.net html  server controlAsp.net html  server control
Asp.net html server controlSireesh K
 
Flutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepFlutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepChandramouli Biyyala
 
Android Layout
Android LayoutAndroid Layout
Android Layoutmcanotes
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART IOXUS 20
 
Responsive web designing ppt(1)
Responsive web designing ppt(1)Responsive web designing ppt(1)
Responsive web designing ppt(1)admecindia1
 
Supporting multiple screens on android
Supporting multiple screens on androidSupporting multiple screens on android
Supporting multiple screens on androidLi SUN
 
Eclipse introduction IDE PRESENTATION
Eclipse introduction IDE PRESENTATIONEclipse introduction IDE PRESENTATION
Eclipse introduction IDE PRESENTATIONAYESHA JAVED
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5IT Geeks
 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects WebStackAcademy
 
Oracle ADF Overview for Beginners
Oracle ADF Overview for BeginnersOracle ADF Overview for Beginners
Oracle ADF Overview for BeginnersJithin Kuriakose
 
New Elements & Features in CSS3
New Elements & Features in CSS3New Elements & Features in CSS3
New Elements & Features in CSS3Jamshid Hashimi
 

What's hot (20)

Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
 
Android resource
Android resourceAndroid resource
Android resource
 
Asp.net html server control
Asp.net html  server controlAsp.net html  server control
Asp.net html server control
 
Flutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepFlutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by Step
 
Notepad ++
Notepad ++Notepad ++
Notepad ++
 
Android media
Android mediaAndroid media
Android media
 
Client side scripting and server side scripting
Client side scripting and server side scriptingClient side scripting and server side scripting
Client side scripting and server side scripting
 
Android Layout
Android LayoutAndroid Layout
Android Layout
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
 
Responsive web designing ppt(1)
Responsive web designing ppt(1)Responsive web designing ppt(1)
Responsive web designing ppt(1)
 
Supporting multiple screens on android
Supporting multiple screens on androidSupporting multiple screens on android
Supporting multiple screens on android
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
 
Eclipse introduction IDE PRESENTATION
Eclipse introduction IDE PRESENTATIONEclipse introduction IDE PRESENTATION
Eclipse introduction IDE PRESENTATION
 
The Power of CSS Flexbox
The Power of CSS FlexboxThe Power of CSS Flexbox
The Power of CSS Flexbox
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
Android intent
Android intentAndroid intent
Android intent
 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects
 
Oracle ADF Overview for Beginners
Oracle ADF Overview for BeginnersOracle ADF Overview for Beginners
Oracle ADF Overview for Beginners
 
New Elements & Features in CSS3
New Elements & Features in CSS3New Elements & Features in CSS3
New Elements & Features in CSS3
 

Similar to Table views

Session 14 - Working with table view and search bar
Session 14 - Working with table view and search barSession 14 - Working with table view and search bar
Session 14 - Working with table view and search barVu Tran Lam
 
Intermediate table views
Intermediate table viewsIntermediate table views
Intermediate table viewsSV.CO
 
MS EXCEL INTRODUCTION DISCUSSING ALL FEATURES.ppt
MS EXCEL INTRODUCTION DISCUSSING ALL FEATURES.pptMS EXCEL INTRODUCTION DISCUSSING ALL FEATURES.ppt
MS EXCEL INTRODUCTION DISCUSSING ALL FEATURES.pptpkm16499
 
04.Navigation on Windows Phone
04.Navigation on Windows Phone04.Navigation on Windows Phone
04.Navigation on Windows PhoneNguyen Tuan
 
Microsoft excel training
Microsoft excel trainingMicrosoft excel training
Microsoft excel trainingEmilyE120
 
It presentation
It presentationIt presentation
It presentationmithu mehr
 
Smooth scrolling in UITableView and UICollectionView
Smooth scrolling in UITableView and UICollectionViewSmooth scrolling in UITableView and UICollectionView
Smooth scrolling in UITableView and UICollectionViewAndrea Prearo
 

Similar to Table views (19)

Table views
Table viewsTable views
Table views
 
Session 14 - Working with table view and search bar
Session 14 - Working with table view and search barSession 14 - Working with table view and search bar
Session 14 - Working with table view and search bar
 
Excel Tables.pdf
Excel Tables.pdfExcel Tables.pdf
Excel Tables.pdf
 
занятие7
занятие7занятие7
занятие7
 
Intermediate table views
Intermediate table viewsIntermediate table views
Intermediate table views
 
Java presentation
Java presentationJava presentation
Java presentation
 
EXCEL
EXCELEXCEL
EXCEL
 
MS EXCEL INTRODUCTION DISCUSSING ALL FEATURES.ppt
MS EXCEL INTRODUCTION DISCUSSING ALL FEATURES.pptMS EXCEL INTRODUCTION DISCUSSING ALL FEATURES.ppt
MS EXCEL INTRODUCTION DISCUSSING ALL FEATURES.ppt
 
04.Navigation on Windows Phone
04.Navigation on Windows Phone04.Navigation on Windows Phone
04.Navigation on Windows Phone
 
Microsoft excel training
Microsoft excel trainingMicrosoft excel training
Microsoft excel training
 
Ms excell
Ms excellMs excell
Ms excell
 
It presentation
It presentationIt presentation
It presentation
 
MS EXCEL
MS EXCELMS EXCEL
MS EXCEL
 
Dreamweaver Ch05
Dreamweaver Ch05Dreamweaver Ch05
Dreamweaver Ch05
 
Html tables
Html tablesHtml tables
Html tables
 
Smooth scrolling in UITableView and UICollectionView
Smooth scrolling in UITableView and UICollectionViewSmooth scrolling in UITableView and UICollectionView
Smooth scrolling in UITableView and UICollectionView
 
Vertica-Database
Vertica-DatabaseVertica-Database
Vertica-Database
 
iOS: Table Views
iOS: Table ViewsiOS: Table Views
iOS: Table Views
 
MS Excel 2013
MS Excel 2013MS Excel 2013
MS Excel 2013
 

More from SV.CO

Handout level-1-module-1
Handout   level-1-module-1Handout   level-1-module-1
Handout level-1-module-1SV.CO
 
Persistence And Documents
Persistence And DocumentsPersistence And Documents
Persistence And DocumentsSV.CO
 
Building complex input screens
Building complex input screensBuilding complex input screens
Building complex input screensSV.CO
 
Working with the Web: 
Decoding JSON
Working with the Web: 
Decoding JSONWorking with the Web: 
Decoding JSON
Working with the Web: 
Decoding JSONSV.CO
 
Saving Data
Saving DataSaving Data
Saving DataSV.CO
 
Alerts notification
Alerts notificationAlerts notification
Alerts notificationSV.CO
 
UI Dynamics
UI DynamicsUI Dynamics
UI DynamicsSV.CO
 
Practical animation
Practical animationPractical animation
Practical animationSV.CO
 
Segues and navigation controllers
Segues and navigation controllersSegues and navigation controllers
Segues and navigation controllersSV.CO
 
Camera And Email
Camera And EmailCamera And Email
Camera And EmailSV.CO
 
Scroll views
Scroll viewsScroll views
Scroll viewsSV.CO
 
Closures
ClosuresClosures
ClosuresSV.CO
 
Protocols
ProtocolsProtocols
ProtocolsSV.CO
 
App anatomy and life cycle
App anatomy and life cycleApp anatomy and life cycle
App anatomy and life cycleSV.CO
 
Extensions
ExtensionsExtensions
ExtensionsSV.CO
 
Gestures
GesturesGestures
GesturesSV.CO
 
View controller life cycle
View controller life cycleView controller life cycle
View controller life cycleSV.CO
 
Controls in action
Controls in actionControls in action
Controls in actionSV.CO
 
Auto layout and stack views
Auto layout and stack viewsAuto layout and stack views
Auto layout and stack viewsSV.CO
 
Custom view
Custom viewCustom view
Custom viewSV.CO
 

More from SV.CO (20)

Handout level-1-module-1
Handout   level-1-module-1Handout   level-1-module-1
Handout level-1-module-1
 
Persistence And Documents
Persistence And DocumentsPersistence And Documents
Persistence And Documents
 
Building complex input screens
Building complex input screensBuilding complex input screens
Building complex input screens
 
Working with the Web: 
Decoding JSON
Working with the Web: 
Decoding JSONWorking with the Web: 
Decoding JSON
Working with the Web: 
Decoding JSON
 
Saving Data
Saving DataSaving Data
Saving Data
 
Alerts notification
Alerts notificationAlerts notification
Alerts notification
 
UI Dynamics
UI DynamicsUI Dynamics
UI Dynamics
 
Practical animation
Practical animationPractical animation
Practical animation
 
Segues and navigation controllers
Segues and navigation controllersSegues and navigation controllers
Segues and navigation controllers
 
Camera And Email
Camera And EmailCamera And Email
Camera And Email
 
Scroll views
Scroll viewsScroll views
Scroll views
 
Closures
ClosuresClosures
Closures
 
Protocols
ProtocolsProtocols
Protocols
 
App anatomy and life cycle
App anatomy and life cycleApp anatomy and life cycle
App anatomy and life cycle
 
Extensions
ExtensionsExtensions
Extensions
 
Gestures
GesturesGestures
Gestures
 
View controller life cycle
View controller life cycleView controller life cycle
View controller life cycle
 
Controls in action
Controls in actionControls in action
Controls in action
 
Auto layout and stack views
Auto layout and stack viewsAuto layout and stack views
Auto layout and stack views
 
Custom view
Custom viewCustom view
Custom view
 

Recently uploaded

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Recently uploaded (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Table views

  • 2. Table views An instance of the UITableView class A subclass of UIScrollView • Displays a list of items • Displays one or possibly thousands of data objects • Presents vertical scrolling and single-column, multiple rows • Provides customizable options
  • 3. Types Table views Dynamic Static When content changes When content doesn’t changes
  • 4. Table view controllers Anatomy of a table view Two possible approaches to add table views: • Add a table view instance directly to a view controller’s view • Add a table view controller to your storyboard
  • 5. Table view styles Anatomy of a table view Plain Grouped
  • 6. Table view cells (UITableViewCell) Anatomy of a table view tableView(_:accessoryButtonTappedForRowWith:) Every row is represented with a table view cell In editing mode, the cell content shrinks Cell content Accessory view Cell content Reordering controlEditing control
  • 7. UITableViewCell properties Anatomy of a table view Cell property Description textLabel UILabel for the title detailTextLabel UILabel for the subtitle imageView UIImageView for an image UITableViewCell class defines three properties for cell content
  • 8. UITableViewCellStyle Anatomy of a table view Storyboard name Programmatic enum name Displays Basic .default textLabel, imageView Subtitle .subtitle textlabel , detailTextLabel, imageView Right detail .value1 textlabel , detailTextLabel, imageView Left detail .value2 textLabel , detailTextLabel
  • 9. Table view readability margins Anatomy of a table view Set tableView.cellLayoutMarginsFollowReadableWidth to true AdjustedDefault
  • 10. Index paths Points to a specific row in a specific section Accessible through the row and section properties • indexPath.row • indexPath.section Values are zero-based
  • 11. Arrays and table views Collection of similar data Typically backed by a collection of model objects var emojis: [Emoji] [Emoji(symbol: Character("😀"), name: "Grinning Face", description: "A typical smiley face.", usage: "happiness"), Emoji(symbol: Character("😕"), name: "Confused Face", description: "A confused, puzzled face.", usage: "unsure what to think; displeasure"), Emoji(symbol: Character("😍"), name: "Heart Eyes", description: "A smiley face with hearts for eyes.", usage: "love of something; attractive")]
  • 12. Cell dequeueing Arrays and table views Table views only load visible cells Saves memory Allows for a smooth flow when scrolling let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
  • 13. Table view protocols Protocol Description UITableViewDataSource Provides data for populating sections and rows UITableViewDelegate (optional) Customizes appearance and behavior
  • 14. Number of sections Table view data source (UITableViewDataSource) optional func numberOfSections(in tableView: UITableView) -> Int If function isn’t provided, the table view assumes one section
  • 15. Number of rows in a section Table view data source (UITableViewDataSource) func tableView(_ tableView: UITableView,
 numberOfRowsInSection section: Int) -> Int
  • 16. Cell for row at index path Table view data source (UITableViewDataSource) func tableView(_ tableView: UITableView, 
 cellForRowAt indexPath: IndexPath) -> UITableViewCell
  • 17. Optional Table view delegate (UITableViewDelegate) Responding to accessory view interaction tableView(_:accessoryButtonTappedForRowWith:) Responding to user interaction tableView(_:didSelectRowAt:)
  • 19. Table Views Unit 4—Lesson 5 Learn how to create dynamic table views by creating an emoji dictionary app
  • 20. Lab: Meal Tracker Unit 4—Lesson 5 Practice with the UITableViewDataSource and UITableViewController by creating an app that will display a list of foods, grouped into three sections, one for each meal of the day
  • 21. © 2017 Apple Inc. This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.