1 / 11

Managing Multiple Views and Segues

Managing Multiple Views and Segues. FA 172 Intro to Mobile App Development. Multiple Views. Recall the RiddleApp the class created on the first day of classes Used a navigation controller, multiple views, and segues

wilbur
Download Presentation

Managing Multiple Views and Segues

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. Managing Multiple Viewsand Segues FA 172 Intro to Mobile App Development

  2. Multiple Views • Recall the RiddleApp the class created on the first day of classes • Used a navigation controller, multiple views, and segues • For today, we will learn to manage multiple views and pass data (objects) between views

  3. Product inventory app • Three projects • ProductInvAppPrototype • Focus on user interface • ProductTest • Focus on testing an existing product class • ProductInvApp • Create the final app

  4. ProductInvAppPrototype • Create a single view project with three buttons • Embed in a navigation controller • Select the view controller, thenNavigator -> Embed In -> Navigation Controller • Add one view controller to the storyboard with a label and an image view • Set label text to some product name (e.g., “Apple”) • Get an image file from the web representing the product (e.g., apple.jpeg), then drag onto“Supporting Files” section • Select the ImageView control, set the image file name

  5. ProductInvAppPrototype • Make two more copies of the view controller (that contains a label and an image) • Update these two copies so the three views represent different products (e.g., apple, orange and pomelo) • Control-drag from each button to a view controller to create the corresponding segues • Select “push” • Build and execute

  6. ProductTest • Create a single-view application with a single button • Add an action connection • Test code will be placedin the corresponding method • Download the Product class (Product.h and Product.m) • Three properties: name, imgFileName, and stockLevel(the first two are of type NSString* the third is an int) • An initWith… method that initializes the properties • Methods to increase/decrease stockLevel:-(void)acceptDelivery:(int) qty-(void) releaseStock:(int) qty • Test the Product class (test code provided in website)

  7. ProductInventoryApp • Follow instructions posted on the course website • Summary • Two view controllers (controlled by a navigation controller), one for the main interface, the other for the product • Product class must be included in the project • Three products created by main view controller • Detail/product view controller has its display based on a product object

  8. ProductInventoryApp: main view • No properties defined in ViewController.h file • No outlet connections • No action connections (button click functionality handled through the segues) • Three product variables declared outside of the methods within the ViewController.m file (these could have been properties but there is no reason to have the data available as properties) • Product objects created within viewDidload method (initialization code executed when view appears) • prepareForSegue method checks which button was pressed (which segue was used) and then sets the appropriate product to be set by the second view

  9. ProductInventoryApp: product view • Separate class (with superclassUIViewController) needs to be created and associated to this view controller • Properties defined in .h file • outlet connections for all controls (except buttons) • One product object (to be set by the main view, but used by this view for display) • Action connections (for the add and remove buttons) • viewDidload contains code (in .m file) that displays details of the product object • Code for the add/remove actions • Retrieve data from the text field and convert to int • Call methods to increase/decrease stock on the product object • Redisplay stock level

  10. ProductInventoryApp

More Related