172
LEARNING IPAD STORYBOARDS IN OBJ-C LESSON 1 Rich Helton [email protected] August 28, 2012

LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Embed Size (px)

DESCRIPTION

LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1

Citation preview

Page 1: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

LEARNING IPAD STORYBOARDS IN OBJ-C

LESSON 1

Rich [email protected]

August 28, 2012

Page 2: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

INTRO TO STORYBOARDS

Page 3: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Disclaimer• This training PowerPoint is in no means reproducing

the documents that it may reference.• Which also means that the references may change

at the owners will. • It only provides references to public sites as a

means for the person reading this to do more research and verify any information at their leisure.

• The purpose of this document’s original intent was simply to provide myself a means of walking through various solutions and reference points.

• I offer no personal support of this document and release it “as is” with no commercial intent.

Page 4: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards -- Apple

• In iOS5, Apple introduced a concept called Storyboards.

• A Storyboard is a visual representation of the user interface of an iOS application.

• See http://developer.apple.com/library/mac/#documentation/General/Conceptual/Devpedia-CocoaApp/Storyboard.html

Page 5: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards -- Apple• A Storyboard is a type of file that is opened

and designed in Xcode’s Interface Builder.• It provides a visual transition to move from

one View to another while visualizing the coding Controllers and Controls.

• It is a workflow of the iPad application. • The Application must be iOS 5 compliant.

Page 6: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards – File type• The Storyboard file is a CocoaTouch XIB

(Apple XML) file type for designing in Interface Builder

Page 7: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

The Storyboard file in Xcode

Page 8: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards -- segue

• The segue manages the transitions between the scenes and passes data with a “sender”.

Page 9: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards -- dock• The dock is used to define outlets and actions

between the view controller and views.

Page 10: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards -- scene• The iPad can have multiple scenes appear at

once, but the scene is similar to a View.

Page 11: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Running a sample showing navigation

Page 13: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards – a collection of controllers• Storyboards holds a set of view controllers.• http://developer.apple.com/library/ios/#feat

uredarticles/ViewControllerPGforiPhoneOS/UsingViewControllersinYourApplication/UsingViewControllersinYourApplication.html#//apple_ref/doc/uid/TP40007457-CH6-SW1

Page 14: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards – a collection of controllers• Storyboards holds a set of view controllers.

Page 15: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards – A few more notes• I like to think of Storyboard as a visual

workflow, that is stored in a storyboard file as a collection of UIKit components, that communicate to the project’s source.

• This workflow will follow the Architecture of a normal UIKit application.

• UIKit Architecture http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/AppArchitecture/AppArchitecture.html

Page 16: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards – A few more notes

Page 17: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards – A few more notesAn Application will be made up of many UIKit

components, like UIApplication, UIWindows and various Controllers.

• Storyborads will extend the Controllers, and conatin a collection Views that the code may work with through its flow.

• UIKit has many framework pieces http://developer.apple.com/library/ios/#Documentation/UIKit/Reference/UIKit_Framework/_index.html

Page 18: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Storyboards – A few more notes

Page 19: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

WALKING THROUGH ACLASSICSAMPLE

Page 21: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

We will start with a Master-Detail Project in Xcode

Page 22: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Master-Detail• A master-detail interface displays a master

list and the details for the currently selected item. Like a table view.

• http://en.wikipedia.org/wiki/Master–detail_interface

Page 24: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

About Xcode

Page 25: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Create a Storyboard Master-Detail project

Page 26: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

It has an iPad and iPhone Storyboard in Universal

Page 27: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Running the blank template already has something …

Page 28: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

WHAT WAS JUST BUILT?

Page 29: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Looking at some of the files• All iOS projects will have a group of files that

will be similar, for example, an AppDelegate, a main function, a .plist, and if a UIKit, a Main Controller, and Main View.

• Big Note, since I am working with both iPhone and iPad storyboards, I will start with the iPhone and copy it to the iPad.

Page 30: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Similar files

Page 31: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

The plist (Property List)• All iOS projects have a .plist, usually named after

the project, that conains icons, gifs, button graphics, global names and settings for the file, etc.

• This is an XML file but viewed as a Property List which is basically a name-value pair of global properties.

• In game programming, there will likely be many plists that contain many, many references to the stored png or gif files.

• Program icons are also referenced here.

Page 33: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

In our example…

Page 34: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

The main function• All C apps, Objective-C apps, C++ apps, and

Console C# programs start with a “main” function.

• In many cases in Objective-C, it will just call the AppDelegate of the project.

Page 35: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Our main function

Page 36: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

The AppDelegate Class• The AppDelegate is the class for startup and

shutdown responsibilities. • It will normally have functions defined like

“FinishLaunching” to start the initial View Controller and before shutting down, potentially save state information.

• It is normally derived from the UIKit’s UIApplicationDelegate.

Page 38: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Our AppDelegate• Notice the “didFinishLaunchingWithOptions”

function launching the Controllers.

Page 39: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

The Controllers• All iOS applications are based on the Model-

View-Controller design pattern.• All will also likely be based on the UiKit

windowing framework. • Since we started with a Master-Detail project,

there will be a Master Controller derived from UITableViewController and a Detail Controller derived from UIViewController. These are tables calling their views.

Page 40: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Our Controllers• Here they are:

Page 41: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Our Controllers in the storyboard

Page 42: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

A few words about MVC• The Model-View-Controller (MVC):

• http://en.wikipedia.org/wiki/Model–view–controller

Page 44: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Notice the Quick Help

Page 45: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

LET’S WORK ON THE PROGRAM

Page 46: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

First, we will add the model BirdSightingFile->New File …

Page 47: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add BirdSighting• Select

• A header, BirdSighting.h, and source file, BirdSighting.m is created:

Page 48: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add some fields to BirdSighting• Add some properties, which are fields or variables, and

an init function to BirdSighting.h.• This will error for now because we declared the

properties and function, but we haven’t defined them with initial values in the .m source.

Page 49: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdSighting fields• These fields will be the Bird’s name, location

of sighting and date seen.

Page 50: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

A note about the jump bar• We can jump to files and functions and

properties within the files by using the navigation jump bar

Page 51: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

We will define the properties and functions

Page 52: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Learning Objective-C• Objective-C, is based on the C language, and

it made sense to me when I thought of it as wrappers, to objectify, the C language.

Page 53: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

@synthesize• We used @synthesize to tell the compiler to

create the accessor methods, i.e. getters and setters.

Page 54: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Now define the Data Controller• We have the getters/setters which is the model,

now define the Controller classes.• We will start with “BirdDataSightingController”

which will be the data controller for loading, saving and accessing the data, which is BirdSighting.

• The BirdSighting is the name, date and location of the Bird.

• BirdDataSightingController will add, load and save an Array List of this data, so we have array model containing a model with name, date and location.

Page 55: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Create the Data Controller• We will create a BirdDataSightingController

just like the BirdSighting class.

Page 56: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Now declare the Data Controller Header

Page 57: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Data Controller• We will have a current count and index to keep

track where we are in the array.• The Array will be NSMutableArray, meaning

modifiable.

Page 58: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdSightingDataController.m

Page 59: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdSightingDataController.m con’t

Page 60: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Check the identity of BirdMasterViewController

Page 61: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Deviations and Disclaimer• I have a referenced an Apple example,

Second iOS App Tutorial and am walking through a similar solution.

• Their example goes into exhaustive detail, while my example is not as detailed.

• My coding style is to get the storyboard mapped out first, and then add the details so several deviations may exist from their example.

Page 62: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

ADDING A TABLE VIEW CONTROLLER

Page 63: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Introduction• UIViewController is one of the referenced

classes that controllers will be derived from.• Like most MVC frameworks, there are

predefined methods that make up the lifecycle of the class.

• Some of these methods that you should understand are viewDidLoad () and viewDidUnload( ) to start. These will be defined regardless of the Controller.

• There are many types of controllers that are prepakaged in UIKit, like UITableViewController.

Page 65: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the View• As mentioned in MVC, all Controllers have

Views.• The View does not have to be code. • As in many iOS products, the View can be a

XIB, iOS XML, file that defines it.• In Storyboards, the View is likely to be

Controller Scene in the Storyboard file.

Page 66: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding AddSightingViewController• Other examples may add this later, as file are

filled in piecemeal. • I simply like to create the files first and edit

the sources as a whole.

Page 67: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

AddSightingViewController.h stub• Now we see that the header is derived ffrom

UITableViewController, no problem.

Page 68: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

AddSightingViewController.m stub• Now we see that the source has many pre-

populated methods to follow the lifecyle of the UITableViewController. Here’s just a few:

Page 69: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the Object• The Controller Scene will likely start from the

Object Library:

Page 70: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the Table View Controller• We will add a UITableViewController and Embed a

Navigation Controller with it:

Page 71: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Setting the UITableViewController• We will set the UITableViewController to the

custom class AddSightingViewController, because we are creating this Scene for this Controller.

Page 72: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Changes the name

Page 74: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Select the Table View in hierarchy, and set to Static Cells in the attributes.

Page 75: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Delete one of the Table View Cells, we only need 2

Page 76: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add labels and text fields for “Bird Name” and “Location”….

Page 77: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add Cancel and Done Bar Button Items….

Page 78: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Create Outlets to the Text Fields to allow communication with the Controller (using control key to Control-Drag and Editor Assistant)

Page 79: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

More on Outlets

• Outlets can be defined through Xcode’s Interface Builder.

• They are defined with the type qualifier IBOutlet. This will give a pointer to the object to allow the Controller to communicate to it.

• See Cocoa Fundamentals Guide https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html

Page 80: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Defining the Outlet in Interface Builder with birdNameInput and locationInput.

Page 81: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Code is generated in the Controller with IBOutlet pointers

• The Controller can now send text to the text field via this IBOutlet pointer.

Page 82: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

It also added some code into the AddSightViewController.m

Page 83: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Now we add Actions that will allow the Buttons to communicate to the Controller

Page 85: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Declare the cancel Action

Page 86: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Declare the done Action

Page 87: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add delegates in the Table View for the text fields

• Control-Drag from the Bird Name and Location text fields to the dock scene’s proxy, yellow orb.

• Select outlet->delegate on both.

Page 88: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add delegates in the Table View for the text fields

Page 89: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Don’t forget, the storyboard file is XIB and we can check to see if the delegate was added to the text field. Add delegates in the Table View for the text fields

Page 90: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

What we have

Page 91: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Part of the XIB

Page 92: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add the protocol methods delegates in the Table View for the text fields

• Control-Drag from the Bird Name and Location text fields to the dock scene’s proxy, yellow orb.

• Select outlet->delegate on both.

Page 93: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add delegate declarations in the header

Page 94: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

After delegate declarations in AddSightingViewController.h

• We will add AddSightingViewControllerDelegate code:

Page 95: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add Table view delegate definitions in AddSightingViewController.m

• We will add Table view delegate code to capture user input from Add Sighting View in the Storyboard:

Page 96: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Pragma marking ..

• The “pragma mark” helps us locate areas with the Navigation Toolbar for the editor:

Page 97: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Now that we have the AddSightingViewController defined, we need to add it to the BirdsMasterViewController to get called from the Application…this will be our connection….

Page 98: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

We will add the Segue through an Add Button on the Master Controller.

Page 99: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the segue with a Control-Dragfrom the (+) to the Navigation Controller

Page 100: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

The modal segue

• A modal segue will present the destination of the view controller, in this instance the Add Sighting View Controller.

• http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/AboutViewControllers/AboutViewControllers.html

• We will also assign the modal segue an identifier to be called referenced by in executing.

• Note: There should be no compile errors yet.

Page 101: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

We will start adding the AddSightingViewController code into the BirdMasterViewController that calls it.

• Start by declaring the imports and interface in BirdMasterViewController.m :

Page 102: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Next, add the piece in BirdMasterViewController’s prepareForSegue to call the Views based on segue name.

Page 103: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Next, add the piece in BirdMasterViewController’s that can call the Cancel and Done buttons.

Page 104: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Compiler errors may start to occur…

• There may be compiler errors in the Main Controller now, especially since the dataController hasn’t been defined in the Main Controller’s header file.

• We need import BirdSightingDataController into BirdsMasterViewController.h.

• And the dataController in the same file.

Page 105: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

DETAILS VIEWS CONTROLLER

Page 106: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsDetailViewController

• The BirdsDetailViewController will display the fields of the BirdSightings model that have already been entered.

• These fields are bird name, location and date.• This will be a UITableViewController that will

display the bird name, location and date fields, set as labels, that are selected from the master scene to display.

Page 107: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsDetailViewController.h

• I added the bird name, location and date in the header file, sometimes I do this ahead of time to prepare the labels in the scene.

Page 108: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Designing the Scene

• We are going to delete Birds Detail View Controller and replace it with a generic Table View Controller.

Page 109: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add the Custom Class name

• Name is BirdsDetailViewController

Page 110: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the segue push from the Master Scene

• We can delete the extra Navigation Controller that had a segue to BirdsDetailViewController because we will be coming from the Master Scene.

Page 111: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the segue push from the Master Scene

• We will Control-Drag from the table cell this time instead of the Add button with a push segue.

Page 112: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the segue name

• Set the segue name to ShowSightingDetails

Page 113: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

We should be here now

Page 114: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Reviewing the segue name

• We can open the storyboard file up as source, XIB, or XML, and see that the segues were named correctly.

Page 115: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Starting on the Table View cells• Set the Content Attribute to Static Cells.

Page 116: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the Labels• Add the labels with from the Object Utilities

and label them Bird Name, Location and Date.

Page 117: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the Labels• Also add the labels to display the bird name, location

and date on the left of the description labels, Duplicate editing may help…

Page 118: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the label names• Control-Drag from the Controllers Object

Dock to each of the display labels.

Page 119: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the label names• Add the appropriate label name,

birdNameLabel, locationLabel, and dateLabel. They should match the header.

Page 120: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the label names• They can be checked by right clicking on the

Label

Page 121: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding the label names• You can also see the link in

BirdsDetailViewController.h, clinking on the reference will take you to the storyboard.

Page 122: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Adding code to BirdsDetailViewController.m

• Add @sythesize to values and create a configView to format the data.

Page 123: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

RECAP SOME OF THE STORYBOARD

Page 124: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

If things worked well…The We have all the major pieces defined.

Page 125: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

More detail …

Page 126: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

More detail …

Page 127: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

This is the MainStoryboard_iPhone

• For simplicity of this first time, we are going to just re-use the same storyboard for iPad.

• We are going to open the stroyboard’s as source and copy the iPhone one into the iPad one.

Page 128: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

This is the MainStoryboard_iPhone

• For simplicity of this first time, we are going to just re-use the same storyboard for iPad.

• We are going to open the stroyboard’s as source and copy the iPhone one into the iPad one. A Text editor, like TextWrangler might be more helpful in keeping the format of the XIB.

• We will address the SplitView issue later.

Page 129: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Now mainStoryboard_iPad

• After copying the iPhone storyboard’s source into the iPad storyboard, the targetRuntime has to be changed from iPhone, iOS.CocoaTouch, to iPad, iOS.CocoaTouc.iPad.

Page 130: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

In Interface Builder

• IB now looks the same for the iPad :

Page 131: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

CONNECTING ALL THE PIECES

Page 132: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

We have all the major pieces defined.

• Up until this point, all of the Storyboard pieces and classes have been created.

• What remains is to start from the beginning and ensure all the pieces are calling each other correctly through their functions.

Page 133: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

We always start with the main.m• The main function always get called first, and it will call the

AppDelegate.• The BirdsAppDelegate.h will declare a UiWindow and be derived

from a UiResponder.

Page 134: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsAppDelegate.m will call …

• Besides stubbed out functions, all the work will be done in didFinishLaunchingWithOptions.

• This function will start with the first controller as the BirdsMasterViewController and passing it the model as BirdsSightingDataController.

• The BirdsSightingDataController will contain a masterBirdSightingList.

• The masterBirdSightingList is an array list of BirdSighting objects.

• The BirdSighting object just contains methods and names for Bird Name, Location and Date.

Page 135: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsAppDelegate.m

Page 136: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsMasterViewController.m will call

• This View will display the array list of BirdSightings.

• If the Add button is pushed, then the AddSightingViewController is called through a delegate to add a new record.

• If the item in the list is selected, the BirdsDetailViewController is displayed with that records BirdSighting information of bird name, location and date.

Page 137: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsMasterViewController.h

• The Master View Header will declare the two controllers that is will call:

Page 138: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsMasterViewController.m

• The prepareForSegue function is very important, and its purpose is to execute the appropriate Controller based on the segue’s name.

Page 139: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Sent to a Controller ..

• If (+), the ShowAddSightingView is referenced to call the AddSightingView Controller.

• If a line item is pressed, the ShowSightingDetails is referenced to call the BirdsDetailViewController.

• A reference will also be set inside BirdsDetailViewController to which row was selected.

Page 140: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

If a detail selected, then BirdsDetailViewController

• This controller will just get the data from row, and filled in the fields that are outlets to update the labels in the Table View:

Page 141: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

If (+) selected, then AddSightingsViewController

• This controller will use outlets and delegates to fill the list from the text fields that are filled out.

• Then based on the next action, cancel or done, it will complete the actions, set as action types, and return to the Master Controller.

Page 142: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add delegate declarations in AddSightingViewController.h

• We will add AddSightingViewControllerDelegate code:

Page 143: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Add Table view delegate definitions in AddSightingViewController.m

• We will add Table view delegate code to capture user input from Add Sighting View in the Storyboard:

Page 144: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

RUNNING THE SAMPLE

Page 145: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Click on to Run and ensure it is set to iPad

Page 146: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Master Controller

Page 147: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Hit Add (+)

• Add (+) goes to AddSightingViewController

Page 148: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Hit Done, adds the record for now, a BirdSighting model.

Page 149: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Select the line takes you to the BirdsDetailViewController. Click Bird Sightings to return to the Main Controller.

Page 150: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Looking at it on the iPhone

Page 151: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

ADDING A A SPLIT VIEW CONTROLLERFOR IPAD

Page 153: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

The Split View Controller ..

• They can be created programmatically.

Page 154: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

For the iPad stroyboard, we will add a SplitViewController

Page 155: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Delete the default attaching views

Page 156: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Set as Initial View and Landscape Orientation

Page 157: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Setting the Split Controller ..

• The relationship has to be set from the SplitView Controller to the Master Controller and Detail Controller as it will now branch off of it from the beginning.

Page 158: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Delete the Segue from Master Controller and Detail View

• Delete the segue from Master Controller to Detail View.

Page 159: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Set the relationships from the Split View Controller to the Master Controller and Detail View with Control-Drag

Page 160: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Set the relationships from the Split View Controller to the Master Controller and Detail View with Control-Drag

Page 161: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Now we have…

Page 162: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

Change the BirdsAppDelegate.m

Page 163: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

We will change the BirdsDetailViewController since it will be in the background as a modal to a UISplitViewControllerDelegate

Page 165: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsDetailViewController.m• We will have to make changes to accommodate

the Master Button as a popover Controller to manage the Detail Scene.

Page 166: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsDetailViewController.m• And accommodate hiding the Master

Controller when the detail is selected…

Page 167: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsMasterViewController.h• Add the detailViewController to be referenced

Page 168: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

BirdsMasterViewController.m• This is be used as the detailViewController that will

be always displayed in the background and changed when a different row is selected in its viewDidLoad

Page 169: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

When Running• And the Master button is selected, the

Master Controller is used as a popup.

Page 170: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

When Running• When the detailed row is selected, it displays the

DetailViewContoller, as before, but now keeps it resident with the detailViewController variable.

Page 171: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

When Running• When the (+) is pushed, it will still call the

prepareForSegue with the ShowAddSightingView and work as before.

Page 172: LEARNING iPAD STORYBOARDS IN OBJ-‐C LESSON 1

CONCLUSION