TableView and TableViewController

Slides:



Advertisements
Similar presentations
Integrating Facebook into iOS Apps 08/25/2011 North Atlanta iOS Developers Meetup Group Presentation.
Advertisements

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.
Site Modules > Page Builder Access the Page Builder module through the Site Modules top navigation link. Access Page Builder from the Site Modules navigation.
Chapter 9 Customizing Data with Web Controls. ASP.NET 2.0, Third Edition2.
Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
An Introduction to Programming with C++ Fifth Edition Chapter 10 Void Functions.
Click to Add Title 0 Click to Add Subtitle To replace this photo with one of your own, go to the master page, delete this image, insert your own image,
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
XP New Perspectives on Microsoft Office Excel 2003, Second Edition- Tutorial 11 1 Microsoft Office Excel 2003 Tutorial 11 – Importing Data Into Excel.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
C++ fundamentals.
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
® IBM Software Group © 2006 IBM Corporation JSF Tab Controls This Learning Module shows how to develop server-side EGL applications with dynamic content.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 9: Customize! Navigating with a Master/Detail.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
CS 104 October 26, 2011 App Inventor. Agenda Discuss guest speakers Discuss quiz Finish Paint Pot Discuss concepts from Chapters 2 & 3 Mole Mash (if time.
Xcode Presentation Tom Pletzke. Creating App from template Launch Xcode Select Tabbed Application.
LATTICE TECHNOLOGY, INC. For Version 10.0 and later XVL Web Master Advanced Tutorial For Version 10.0 and later.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Advanced Report and Form Techniques – Project 7. 2 Project 7 Overview This project shows how to create queries for reports, add command buttons to forms,
Edit a Page Detailed Front End To edit any information on your web page, you will have to login to the admin tool to change it.
Introduction to Objective-C and Xcode (Part 3) FA 175 Intro to Mobile App Development.
User Experience with iPads/Mobile Devices and VitalSource eBooks NOTE: all screenshots in this presentation were taken on an iPad 2.
PHP meets MySQL.
Domain 3 Understanding the Adobe Dreamweaver CS5 Interface.
Copyright 2007, Information Builders. Slide 1 Understanding Basic HTML Amanda Regan Technical Director June, 2008.
GEMVC. The Setup Folders Views Value Objects (VOs) Custom Events Service CFCs Controller Model Application Main MXML.
Android Boot Camp for Developers Using Java, 3E
Caching Chapter 12. Caching For high-performance apps Caching: storing frequently-used items in memory –Accessed more quickly Cached Web Form bypasses:
Moodle with Style Integrating new technologies to empower learning and transform leadership.
Navigation in iPads splitViewController. Overview Create a Master-Detail application Switch Device Family to iPad Give the project a name and click “Use.
IReport Demo Spring 2008 OEDSA Conference. Report Properties.
Managing Multiple Views and Segues FA 172 Intro to Mobile App Development.
+ An Intro To Xcode By Sarah Montroy. + What is Xcode?
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
Course Summary Xcode & iPhone Simulator
Chapter 4 Introduction to Classes, Objects, Methods and strings
Nav Controllers UINavigationController. Overview Nav Controller basics Like a tabview controller, a navViewController manages views A navigationViewController.
ActionScript 3 Using Sound Related Classes by Martin Stanhope The University of Bolton.
User Interface Objects From Beginning iPhone 4 Development and The iPhone Developer’s Cookbook (Chapter 4)
1 Guide to Oracle10G CHAPTER 7: Creating Database Reports 7.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Table Views UITableView.
Page Designer Storyboard J. A. Fitzpatrick December 2004.
® IBM Software Group © 2006 IBM Corporation JSF Rich Text Area Component This Learning Module describes the use of the JSF Rich Text Area component – for.
Visual Basic for Application - Microsoft Access 2003 Finishing the application.
1 Reverse a String iPhone/iPad, iOS Development Tutorial.
WaveMaker Visual AJAX Studio 4.0 Training Java Script Events.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
CHAPTER 7 LESSON C Creating Database Reports. Lesson C Objectives  Display image data in a report  Manually create queries and data links  Create summary.
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Title of your site Title of your page Text and images arranged on the page in the design of your choice. Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page.
Please wait, Our presentation will be starting soon. Use Alt+Tab key to go to other applications while the presentation is running. Use Esc key to stop.
CHAPTER 7 LESSON B Creating Database Reports. Lesson B Objectives  Describe the components of a report  Modify report components  Modify the format.
Course Summary Xcode & iPhone Simulator
Views in iOS Mobile apps for iPhone & iPad Telerik Software Academy
Objects First with Java A Practical Introduction using BlueJ
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
A lighting tour™ to iOS Plus some fun stuff
Objects First with Java A Practical Introduction using BlueJ
EEC-492/693/793 iPhone Application Development
Objects First with Java A Practical Introduction using BlueJ
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
User Experience with iPads/Mobile Devices and VitalSource eBooks
Presentation transcript:

TableView and TableViewController View that looks like the view on a telephone/address book The Master/Detail template provides the skeleton code for it MasterViewController extends the UITableViewController class Need to override various methods inherited from UITableViewController

Table View A table view displays a list of labels arranged in sections and rows We can decide the number of sections, the header for each section, and the rows of each section We can also retrieve what row of what section the user selected and execute some code based on that

Number of sections To define the number of sections, override numberOfSectionsInTableView:, return the desired number of sections (2 or 3 for example) -(NSInteger) numberOfSectionsInTableView(UITableView *) tableView { return 3; }

Number of rows per section To define the number of rows per section, override tableView:numberOfRowsInSection:, return the desired number of rows per section (use the section parameter); method header is -(NSInteger) tableView:( UITableView * ) tableView numberOfRowsInSection:( NSInteger ) section

Number of rows per section switch( section ) { case 0: // section 0 return 4; // 4 rows in section 0 case 1: // section 1 return 2; // 2 rows in section 1 case 2: // section 2 return 3; // 3 rows in section 2 }

Header of each section To define the title for each section, override tableView:titleForHeaderInSection:, define the desired title for each section; method header is -(NSString *) tableView:( UITableView * ) tableView titleForHeaderInSection: ( NSInteger ) section

Header for each section switch( section ) { case 0: // section 0 return @”CS courses”; case 1: // section 1 return @”CT courses”; case 2: // section 2 return @”AE courses”; }

Putting data in each table cell A cell of a table view is defined by 2 values: its section index and its row index within that section Example: a cell can be in section 0, row 3, or in section 1, row 0

Accessing each table cell The class NSIndexPath encapsulates the concept of how to access a cell in a table It has 2 properties, section and row If indexPath is aNSIndexPath object indexPath.section  section indexPath.row  row

Putting data in each table cell To put data in the table, override tableView:cellForRowAtIndexPath:, define the desired data for each row of each section; method header is -(UITableViewCell *) tableView:( UITableView * ) tableView cellForRowAtIndexPath : ( NSIndexPath * ) indexPath

Putting data in each table cell That method returns a UITableViewCell based on the NSIndexPath of that cell So inside the method, we create a UITableViewCell object, set the text inside it based on its index path, i.e. section and row, and return it

Putting data in each table cell The template already provides part of the code for that method (the part creating the UITableViewCell) A UITableViewCell has access to various properties and methods to manage its contents and behavior, for example image displayed and text

Putting data in each table cell Among other things, a UITableViewCell has a property called textLabel, a UILabel; so we need to set the text inside that label [[cell textLabel] setText:@”…”]; // OR cell.textLabel.text = @”…”; … depending on the value of indexPath.section and indexPath.row

Touching a table cell We may want to execute some code whenever the user touches a table cell (typically, go to the detail view) For this, we need to override the method tableView:didSelectRowAtIndexPath:

Touching a table cell The method header is - (void) tableView:(UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath Again, we can retrieve the section selected with indexPath.section and the row selected with indexPath.row

Go to Detail View Inside the tableView:didSelectRowAtIndexPath: method, we can add code to pass data to the DetailViewController (but it is only set for the iPad – more on that later)

iPhone vs iPad: 1 vs 2 View Controllers for detail View We may only want to have 1 View Controller for the detail view (as in the skeleton) Or we may want to have 2 View Controllers (i.e. add one): one for the iPad detail View and one for the iPhone detail View

Titles, .. - iPhone Edit in storyboard Change “Master” to … Change “Detail” to …

Titles, .. - iPad Title is set in splitViewController:willHideViewController:withBarButtonItem:forPopoverController: method  change the title of barButtonItem if you want to change the title NSLocalizedString relates to locale (applicable to apps in several languages: English, Spanish, French, ..)

Master/Detail – Going Back  The title shows up on the main page and the button (with the same title) shows up on the second page; clicking on it brings you back to the front page The Master/Detail template includes the corresponding code to provide this functionality

Passing data Inside the DetailViewController class, we can have instance variables and methods so that we can pass data to it from the root view controller Both view controllers can even share the same object (for example a TicTacToe object)

Passing data Most likely, the detail view will depend on two things: the section and the row selected by the user in the master view  Have 2 int instance variables, section and row in the detail view controller Have a method setting them -(void) updateSection: (int) newSection Row: (int) newRow;

Passing data Set them to their new values whenever the user goes to the detail view, i.e. whenever the user clicks on a row of a section, i.e. whenever the method tableView:didSelectRowAtIndexPath: is called

Passing data [self.detailViewController setSection: indexPath.section Row: indexPath.row]; Now we can customize the detail view based on the values of section and row in the detail view controller

Passing data Where should you customize the view in the detail view controller class? Not every method is called every time the view shows; a lot of them are only called the first time the view is created  can call viewWillAppear: (called every time we show the view, not just when the view is loaded in memory)

IPad Test the app with the iPad simulator  detail view does not change Problem: We did not update the label (detailDescriptionLabel) inside the detail View

IPad self.detailDescriptionLabel.text = [NSString stringWithFormat: @”section %d row %d”, section, row];  detail View is updated correctly

IPad If you test the app inside the iPad simulator in vertical position, the popover does not dismiss when you make a selection  we need to add code to dismiss it

IPad Inside the DetailViewController class, access the popover controller using self.masterPopoverController And use the dismissPopoverAnimated: method to dismiss it [self.masterPopoverController dismissPopoverAnimated: YES];

IPhone Problem: no data is passed when testing the app in the iPhone simulator Inside tableView:didSelectRowAtIndexPath:, self.detailViewController is null  the call to updateRow:Section is a no-op

IPhone BUT prepareForSegue:sender: is called before tableView:didSelectRowAtIndexPath: AND we have access to the View Controller of the detail View via [segue destinationController]

IPhone  Inside prepareForSegue:sender: self.detailViewController = [segue destinationController];  inside tableView:didSelectRowAtIndexPath: self.detailViewController is no longer null