Table Views UITableView.

Slides:



Advertisements
Similar presentations
Table Views UITableView. Overview Table view basics Tables display lists of data Each item in a tables list is a row Tables can have an unlimited number.
Advertisements

How can Microsoft PowerPoint 2007 help you share information?
MS® PowerPoint.
TableView and TableViewController
INSERT A SYMBOL Determine the Symbol to insert Determine the Symbol to insert Computer don’t just work with letters and numbers. In the global economy.
After attending this workshop, students should be able to complete the following tasks involving MS Word:
Word Skills Stumped by Word’s formatting tools? Here’s some help to get you started  Ruler / Tab Bar Ruler / Tab Bar  Bullets / Numbering / Sections.
The Problem: iPhone UI Navigation I want to have a TableView that works INSIDE a TabView.
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
XP New Perspectives on Microsoft Office Excel 2003, Second Edition- Tutorial 11 1 Microsoft Office Excel 2003 Tutorial 11 – Importing Data Into Excel.
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
1 Agenda Views Pages Web Parts Navigation Office Wrap-Up.
This is Google Drive. It stores all the documents you have made here.
A Prezi presentation is like creating a mind map. It is created on a blank canvas and you decide where the information goes on this canvas.
Chapter 4 Dreamweaver: Part II The Web Warrior Guide to Web Design Technologies.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Enhancing and Customizing a Presentation
Xcode Presentation Tom Pletzke. Creating App from template Launch Xcode Select Tabbed Application.
Xcode testing Using XCTest.
Creating a Presentation
Project 9 Using Visual Basic for Applications (VBA) to Customize and Automate Excel Jason C. H. Chen, Ph.D. Professor of Management Information Systems.
CIS 205—Web Design & Development Flash Chapter 1 Getting Started with Adobe Flash CS3.
Microsoft PowerPoint Getting Started Guide Prepared for Towson University Dr. Jeff M. Kenton Amy Chase Martin 2007.
Microsoft Outlook 2007 Basics Distance Learning (860) 343 – 5756 Chapman 633/632 Middlesex Community College Visit
iOS components in Swift
MICROSOFT WORD 2007 INTERMEDIATE/ADVANCED. CREATE A NEW STYLE BASED ON A SELECTED TEXT HOME tab > STYLES group dialog launcher > at the bottom of the.
CPG 4331 Class Agenda Word  Getting Started  Editing Documents  Changing Views in Documents  Format Text / Format Documents  Work With Tables  Work.
Remember…  Please do not…  Change the background.  Change the icons.  Change the font. Use Times New Roman (size 12 font).  Use color. We cannot print.
Excel CREATING A WORKSHEET AND CHART. Personal Budget Worksheet We will create a personal budget worksheet that shows you income each month and your expenses.
Tabbed Views UITabBarController. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and.
Navigation in iPads splitViewController. Overview Create a Master-Detail application Switch Device Family to iPad Give the project a name and click “Use.
IOS with Swift Hello world app.
Adobe InDesign CS2—Revealed SETTING UP A DOCUMENT.
1 After completing this lesson, you will be able to: Change the layout of a slide. Insert a clip art image. Scale an image. Insert and format a Microsoft.
Gestures UIGestureRecognizer.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Course Summary Xcode & iPhone Simulator
Nav Controllers UINavigationController. Overview Nav Controller basics Like a tabview controller, a navViewController manages views A navigationViewController.
Orientation Configuration adapting to orientation changes.
Welcome to PowerPoint for Beginners In-Tech Training Elementary School Teachers Day 2 January 13 and 14, 2003.
Creating Google Sites Laura Assem, Director of Technology.
By: Ms. Abeer Helwa 1. CREATE A WORD DOCUMENT 2 Blank document Templates To create a new blank document: click the File tab and click Blank document.
Chapter 3 Automating Your Work. It is frustrating when you have to type the same passage of text repeatedly. For example your name and address. Word includes.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
1 UI Alert View iPhone/iPad, iOS Development Tutorial.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
Remember…  Please do not…  Change the background.  Change the icons.  Change the font. Use Times New Roman (size 12 font).  Use color. We cannot print.
Transportation Agenda 77. Transportation About Columns Each file in a library and item in a list has properties For example, a Word document can have.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
Progress and Outcome Measures - Part 3 Progress and Outcome Measures Part 3, Slide 1Copyright © 2004, Jim Schwab, University of Texas at Austin.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
MS WORD INFORMATION TECHNOLOGY MANAGEMENT SERVICE Training & Research Division.
PowerPoint Chapter 1 Creating and Editing a Presentation with Clip Art Discovering Computers & Microsoft Office 2010.
1 Word Processing Intermediate Using Microsoft Office 2000.
WebViews UIWebView. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and xib) that manages.
Microsoft Excel 2007 Noris Bt. Ismail Faculty of Information and Communication Technology Tel : (Ext 8408) BCOMP0101.
Course Summary Xcode & iPhone Simulator
A step-by-Step Guide For labels or merges
UITableView API A table view is an instance of the UITableView class. Created given... an area on the screen, and A table style. Rows are created using.
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
Chapter 2 – Introduction to the Visual Studio .NET IDE
CSC 581: Mobile App Development
CSC 581: Mobile App Development
EEC-492/693/793 iPhone Application Development
Apple Xcode with Swift Demo
EEC-492/693/793 iPhone Application Development
CSC 581: Mobile App Development
Presentation transcript:

Table Views UITableView

Overview Table view basics Reference: Tables display lists of data Each item in a table’s list is a row Tables can have an unlimited number of rows Tables can only be one column wide (but see later slides) Reference: Apple Developer Reference Chap 8 in “Beginning iPhone Development with Swift”

Views vs Cells A table view is a subclass of a view Technically it is a UITableView Each visible row in a table is an instance of a UITableViewCell Table view cell Table view

Table Data Table views do not store all the data Rather they just store data for the rows that are displayed They get their configuration data from the object that conforms to the UITableViewdelegate protocol They get their row data from the object that conforms to the UITableViewDataSource protocol

Table Cells Each row is represented by a single UITableViewCell Each UITableViewCell object can be configured with an image, some text, an optional accessory icon If you need more data (or columns) in a cell you can create a subview Can do this programmatically Can do this in IB

Grouped Tables Plain Tables. The default style. May be indexed Grouped Tables. Each group is a set of rows embedded in a rounded rectangle. Can consist of a single group Each division in a table is known to your data source as a section In a grouped table, each group is a section In an indexed table, each indexed grouping of data is a section. E.g., names beginning with ‘A’, names beginning with ‘B’, etc.

Indexed vs Grouped Indexed Table Grouped Table

The app We’ll create a simple app with a single table view Later will create a navigation app that uses tables

Creating Create a new project Select single view application Choose a name, etc. Make sure the language is Swift and it’s for the iPhone Leave unchecked: use core data Choose a place to save Do not need to use git

What did you get? Look at the file navigator Normal appDelegate, viewcontroller, and Main.storyboard

Creating the view Click on the Main.Storyboard to show IB Find a Table View (not a TableViewController) in the library and drag to the view. The table view should automatically size itself to fill the entire view. Click on the pin icon at bottom Check the Constrain to margins checkbox click on all 4 struts change all 4 distances to 0 change Update Frames to Items of New Constraints click the Add 4 Constraints button

Creating the view Open the hierarchical view by clicking on the Document Outline button Click on the Table View, bring up the connections inspector Under the outlets section drag from dataSource to View Controller in the outline Under the outlets section drag from delegate to View Controller in the outline This makes the viewController both the data source and delegate for the table.

Delegates & Datasources Delegate: an object that takes responsibility for doing certain tasks on behalf of another object. a delegate contains methods that another object calls when certain events happen or when something needs to be done. Datasource: an object that supplies information to another object. a datasource knows about the model and can get information from it on behalf of view object

Delegates & Datasources Calls when something happens object These can be the same object datasource Calls to get information

Creating the controller in the Project Navigator click on the ViewController.swift file and add the bold: class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { private let dwarves = [ "Sleepy", "Sneezy", "Bashful", "Happy", "Doc", "Grumpy", "Dopey", "Thorin", "Dorin", "Nori", "Ori", "Balin", "Dwalin", "Fili", "Kili", "Oin", "Gloin", "Bifur", "Bofur", "Bombur" ] let simpleTableIdentifier = "SimpleTableIdentifier" This makes the view controlleraable to be both the data source and the delegate of a table. The array will hold our data. Normally the data will reside in the model class not the controller class. UITableViewDataSource and UITableViewDelegate are protocols

Creating the controller II in the Project Navigator click on the ViewController.swift file and add the bold: func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return dwarves.count } We need as many rows as we have array entries. This method is called by the table when it needs to know how many rows are in the section (number of sections is 1 by default)

Creating the controller II in the Project Navigator click on the ViewController.swift file and add the bold: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { This method is called by the table when it needs a cell to display. We must return a UITableViewCell Method body on next slide….

Creating the controller II We check to see if there is an unused cell of the correct type that we can reuse. var cell = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentif ier) as? UITableViewCell if (cell == nil) { cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: simpleTableIdentifier) cell!.textLabel?.text = dwarves[indexPath.row] return cell } The reuse identifier is used to identify the type of cell If there was no leftover cell we have to create a new one. Use default style; there are others! The indexPath parameter contains the row (and section) number that the table will use this cell for. The label text is what shows up in the row. We return this cell; it will be displayed as the next row As table rows scroll out of view, they are placed into a queue of cells to be reused. If memory gets low, they are discarded.

Run! Should see a table. But can’t select anything yet! Problem: tables runs under the nav bar. To fix: go to storyboard, select the tableView in the doc outline on the storyboard, resize (don’t grab) the top of the view down until you see the blue guideline under the status bar Click the tie-fighter icon (Resolve Auto Layout Issues) at the bottom and click Update Constraints. Run again

More on Cells Add image Add icon image to Xcode (see LectureProgramminstar.png) Change the method on next slide(assuming icon has name star.png)

More on Cells func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentifier) as? UITableViewCell if (cell == nil) { cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: simpleTableIdentifier) } let image = UIImage(named: "star") cell!.imageView?.image = image let highlightedImage = UIImage(named: "star2") cell!.imageView?.highlightedImage = highlightedImage cell!.textLabel?.text = dwarves[indexPath.row] cell!.textLabel?.font = UIFont .boldSystemFontOfSize(50) return cell! }}

More on Cells Add detail text Subtitle Add detail text Cells can have additional (“detail”) text. Must change the cell “style”. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentifier) as? UITableViewCell if (cell == nil) { cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: simpleTableIdentifier) } let image = UIImage(named: "star") cell!.imageView?.image = image let highlightedImage = UIImage(named: "star2") cell!.imageView?.highlightedImage = highlightedImage if indexPath.row < 7 { cell!.detailTextLabel?.text = "Mr Disney" } else { cell!.detailTextLabel?.text = "Mr Tolkien" cell!.textLabel?.text = dwarves[indexPath.row] cell!.textLabel?.font = UIFont .boldSystemFontOfSize(50) return cell! }} Must change the style of the cell for the subtitle to show up! We’ll use different subtitles for the first 7 rows (0-6). Other styles: initWithStyle:UITableViewCellStyleValue1 initWithStyle:UITableViewCellStyleValue2

Detecting Row Selection Two events you can detect: When a row will be selected. Can prevent or change the selection When a row has been selected. Can react to the selection.

Detecting Row Selection When a row will be selected. Can prevent or change the selection Add to viewController.m: func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? { if indexPath.row == 0 { return nil } else if (indexPath.row % 2 == 0){ return NSIndexPath(forRow: indexPath.row + 1, inSection: indexPath.section) } else { return indexPath } indexPath contains the number of the row that was selected. Prevents row 0 from being selected. When an even row is touched, the following row is selected

Detecting Row Selection When a row has been selected. Put up alert box: Add to viewController.m: func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let rowValue = dwarves[indexPath.row] let message = "You selected \(rowValue)" let controller = UIAlertController(title: "Row Selected", message: message, preferredStyle: .Alert) let action = UIAlertAction(title: "Yes I Did", style: .Default, handler: nil) controller.addAction(action) presentViewController(controller, animated: true, completion: nil) } Find the name of the dwarf for the selected row A typical alert box Now deselect the row

Other modifications to cells See Beginning iOS 6 Development chapter 8 Set indent level of row Set font size, row height Customize table view cells Programmatically Using the storyboard Add groups Add indexes Add navigation bar or search bar Detail disclosure buttons (chapter 9)