1 / 21

Chapter 6 Flag Quiz Game App

Chapter 6 Flag Quiz Game App. More IB: UISegmentedControl, UISwitch, images Using a Utility template that provides skeleton code supporting 2 views: a front side view and a flip side view Memory Management. Utility Template.

dextra
Download Presentation

Chapter 6 Flag Quiz Game App

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6 Flag Quiz Game App • More IB: UISegmentedControl, UISwitch, images • Using a Utility template that provides skeleton code supporting 2 views: a front side view and a flip side view • Memory Management

  2. Utility Template • The Utility template provides several skeleton classes with some functionality already implemented to support and to go back and forth between 2 views: • The frontside view (the game) • The flipside view (the settings of the game: easy, average, difficult, ..)

  3. Utility Template • Open a project choosing the Utility template • Build and Run • Flip back and forth between the 2 views using the info and done button • Let’s look at the info button

  4. Utility Template • Open the Main_iPhone storyboard file • Click on the info button • Open the Attributes Inspector • Type of button is Info Light (UIButtonTypeInfoLight value of UIButtonType)

  5. MainViewController.h • Imports FlipsideViewController.h • Extends UIViewController • Implements FlipsideViewControllerDelegate protocol (inside angle brackets) and UIPopoverControllerDelegate • Protocol = similar to interface in Java (a way to implement multiple inheritance)

  6. Protocol • Syntax: • @interface SubclassName : SuperclassName <protocolName1[, protocolName2, ..]> • @interface A : B <C, D, E> • Class A extends class B and implements protocols C, D and E

  7. FlipsideViewController.h • FlipsideViewControllerDelegate protocol is declared inside FlipSideViewController.h • It has one method: flipsideViewControllerDidFinish: • That method, implemented in MainViewController.m, returns the app to the main view when the user touches the Done button in the flip side view

  8. FlipsideViewController.h • Why is flipsideViewControllerDidFinish: implemented in MainViewController.m? • Because MainViewController implements the FlipsideViewControllerDelegate protocol

  9. Delegate • Has a property, named delegate, of type id (generic object) that implements the FlipsideViewControllerDelegate • Inside the class, we can access it via self.delegate • It represents the MainViewController object controlling the front view

  10. Delegate • We can use it to call flipsideViewControllerDidFinish: • We can type cast it to be a MainViewController object •  it enables communication between the 2 views

  11. View Transitions • Look at the done method (in FlipsideViewController.m): It makes the app go from the flip side to the front side • Look at the Main_iPhone storyboard file, click on the info button, open the Connections Inspector: this makes the app go from the front side to the flip side

  12. done method • Using the delegate, it calls the flipsideViewControllerDidFinish method • If the device is an iPhone, that method calls dismissViewControllerAnimated:completion: (of the class UIViewController); that returns the app to the main view

  13. Info button • Connections inspector  Triggered Segues • Says “Modal”, FlipSide View Controller •  When the button is clicked, a View controlled by the FlipsideViewController will be on top of the View stack • Also, the prepareForSegue:sender: method (of the UIViewController class) executes (it is called automatically)

  14. Info button • A segue (UIStoryboardSegue class) is a transition between 2 View Controllers; it is created by the storyboard runtime • If we want to initiate a segue by code, we can: we call the performSegueWithIdentifier:sender: method

  15. Info button • We could write our own method and link it to a “Touch Up Inside” event on the Info button • It would create a FlipsideViewController object and push its View to the top of the stack

  16. Views • Views are managed in a stack: • Present a view  add view on top of the stack • Dismiss a view  remove view from the stack • The view at the top of the stack is the one that the user sees

  17. Front side and Flip side • Next: need to pass information between the views (back and forth) • In the front side view, we will have a Model object as an instance variable • Via the delegate, the Flipside view will have access to that Model object

  18. Front side and Flip side • When things change on the flip side, we will update the Model object • Then when we go back to the front side, we will be able to update the view accordingly • Essentially, the Model object is accessible from both views

  19. Updating the front side • Inside the flip side view controller, we access the delegate like this: (MainViewController *) self.delegate • And with it we have access to the Model object

  20. iPad • This skeleton also applies to the iPad • Main_iPad storyboard • Only “one” View • The flip side View is a popover View •  Visible when user clicks on Info •  Dismissed when the user clicks on Done

  21. Memory Management • Our code is getting more and more complex, and we have objects everywhere, several views that come and go, .. • We need to look at how memory is managed

More Related