SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
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.

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to xcode
Introduction to xcodeIntroduction to xcode
Introduction to xcode
Sunny Shaikh
 
Rapid Prototyping & Axure RP
Rapid Prototyping & Axure RPRapid Prototyping & Axure RP
Rapid Prototyping & Axure RP
ISsoft
 

Was ist angesagt? (20)

Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
 
Swift UI - Declarative Programming [Pramati Technologies]
Swift UI - Declarative Programming [Pramati Technologies]Swift UI - Declarative Programming [Pramati Technologies]
Swift UI - Declarative Programming [Pramati Technologies]
 
Quill vs Slick Smackdown
Quill vs Slick SmackdownQuill vs Slick Smackdown
Quill vs Slick Smackdown
 
Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6
 
Accessibility In Mobile Dev LifeCycle.pptx
Accessibility In Mobile Dev LifeCycle.pptxAccessibility In Mobile Dev LifeCycle.pptx
Accessibility In Mobile Dev LifeCycle.pptx
 
Intro to UIKit • Made by Many
Intro to UIKit • Made by ManyIntro to UIKit • Made by Many
Intro to UIKit • Made by Many
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
 
Introduction to xcode
Introduction to xcodeIntroduction to xcode
Introduction to xcode
 
Optional in Java 8
Optional in Java 8Optional in Java 8
Optional in Java 8
 
Android Layout.pptx
Android Layout.pptxAndroid Layout.pptx
Android Layout.pptx
 
A coding fool design patterns
A coding fool design patternsA coding fool design patterns
A coding fool design patterns
 
Intro to Information Architecture for Web Sites
Intro to Information Architecture for Web SitesIntro to Information Architecture for Web Sites
Intro to Information Architecture for Web Sites
 
Rapid Prototyping & Axure RP
Rapid Prototyping & Axure RPRapid Prototyping & Axure RP
Rapid Prototyping & Axure RP
 
Exploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in ScalaExploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in Scala
 
Build a minial DBMS from scratch by Rust
Build a minial DBMS from scratch by RustBuild a minial DBMS from scratch by Rust
Build a minial DBMS from scratch by Rust
 
Android Development Workshop
Android Development WorkshopAndroid Development Workshop
Android Development Workshop
 
Flutter & Firebase BootCamp.pdf
Flutter & Firebase BootCamp.pdfFlutter & Firebase BootCamp.pdf
Flutter & Firebase BootCamp.pdf
 
The Play Framework at LinkedIn
The Play Framework at LinkedInThe Play Framework at LinkedIn
The Play Framework at LinkedIn
 
Developing Cross platform apps in flutter (Android, iOS, Web)
Developing Cross platform apps in flutter (Android, iOS, Web)Developing Cross platform apps in flutter (Android, iOS, Web)
Developing Cross platform apps in flutter (Android, iOS, Web)
 
Google flutter and why does it matter
Google flutter and why does it matterGoogle flutter and why does it matter
Google flutter and why does it matter
 

Ähnlich wie 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
 

Mehr von 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
 

Kürzlich hochgeladen

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

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.