Assignment #3 Task #8

Please note, this blog entry is from a previous course. You might want to check out the current one.

Make your Calculator work on the iPad too (in the same application, i.e., a Universal application) by having two storyboards, one for the iPhone (described above) and one for the iPad that uses a UISplitViewController to present your old Calculator MVC on the left of the screen (or in a popover) and your new graphing MVC on the right.

We start by changing Devices in in the Targets Summary tab from iPhone to Universal, rename the existing storyboard to iPhone.Storyboard and adjust the settings for the iPhone Deplayment Info accordingly.

Create a new storyboard using File -> New -> File… -> User Interface -> iPad and adjust the settings for the iPad Deplayment Info to the new storyboard.

Go to your iPhone storyboard, copy everything and paste it to your new iPad storyboard. Remove the navigation view controller and the segue between your calculator and your graph view.

Drag out a split view controller, remove everything storyboard just created but the actual split view controller and connect your calculator as master and the graph as detail view.

Allow rotation of the calculator view for the iPad:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (self.splitViewController) return YES; 
    else return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

Add a toolbar to both the master and the detail view an name them accordingly. This is might be a little bit more challenging inside the toolbar as we need two Flexible Space Bare Button Items an one plain Bar Button Item. To display the program description in the graph view create an outlet for the plain item e.g. called forumula and set its title in setProgram.

Add the protocol SplitViewBarButtonItemPresenter.h from the psychologist project to your calculator project. Make the graph view controller the <SplitViewBarButtonItemPresenter>, synthesize splitViewBarButtonItem and add handleSplitViewBarButtonItem: and setSplitViewBarButtonItem: from the psychologist project.

Make the calculator view controller the <UISplitViewControllerDelegate>. Add

self.splitViewController.delegate = self;

to its awakeFromNib and add splitViewBarButtonItemPresenter and the splitViewController methods from the psychologist project.

Finally connect the Graph button to a new function to update the program:

- (IBAction)graphButtonPressed {
    id gVC = [self.splitViewController.viewControllers lastObject];
    if (![gVC isKindOfClass:[GraphViewController class]]) return;
    [gVC setProgram:self.brain.program];
}
FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.