Upgrade in Utility App from SDK 2.2.1 to SDK 3.0

July 7, 2009 § 1 Comment

In SDK 2.2.1, infoButton is just a UIButton that is controlled by the toggleView: method in RootViewController.h.

SDK 3.0 reveals a new architecture. RootViewController .h & .m files are eliminated from the directory of “Application Delegate”. <FlipsideViewControllerDelegate> and showInfo: method are added to the MainViewConroller .h file.

New architecture in SDK 3.0 is a better implementation because it eliminates the complexity of RootViewController. It is complicated to pass data between MainViewController and FlipsideViewController via the middleman, RootViewController.

In SDK 2.2.1 RootViewController.m:

#import <UIKit/UIKit.h>
@class MainViewController;
@class FlipsideViewController;
@interface RootViewController : UIViewController {
UIButton *infoButton;
MainViewController *mainViewController;
FlipsideViewController *flipsideViewController;
UINavigationBar *flipsideNavigationBar;
}
@property (nonatomic, retain) IBOutlet UIButton *infoButton;
@property (nonatomic, retain) MainViewController *mainViewController;
@property (nonatomic, retain) UINavigationBar *flipsideNavigationBar;
@property (nonatomic, retain) FlipsideViewController *flipsideViewController;
– (IBAction)toggleView;
@end

In RootViewController.m:

– (IBAction)toggleView {
/*
This method is called when the info or Done button is pressed.
It flips the displayed view from the main view to the flipside view and vice-versa.
*/
if (flipsideViewController == nil) {
[self loadFlipsideViewController];
}
UIView *mainView = mainViewController.view;
UIView *flipsideView = flipsideViewController.view;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];
if ([mainView superview] != nil) {
[flipsideViewController viewWillAppear:YES];
[mainViewController viewWillDisappear:YES];
[mainView removeFromSuperview];
[infoButton removeFromSuperview];
[self.view addSubview:flipsideView];
[self.view insertSubview:flipsideNavigationBar aboveSubview:flipsideView];
[mainViewController viewDidDisappear:YES];
[flipsideViewController viewDidAppear:YES];
} else {
[mainViewController viewWillAppear:YES];
[flipsideViewController viewWillDisappear:YES];
[flipsideView removeFromSuperview];
[flipsideNavigationBar removeFromSuperview];
[self.view addSubview:mainView];
[self.view insertSubview:infoButton aboveSubview:mainViewController.view];
[flipsideViewController viewDidDisappear:YES];
[mainViewController viewDidAppear:YES];
}
[UIView commitAnimations];
}

In SDK 3.0 MainViewController.h:

#import “FlipsideViewController.h”
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate> {
}
– (IBAction)showInfo;
@end

In MainViewController.m:
– (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
– (IBAction)showInfo {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@”FlipsideView” bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}

Advertisements

§ One Response to Upgrade in Utility App from SDK 2.2.1 to SDK 3.0

  • Platsek says:

    Hi! Would you be so nice to quickly recreate the Utility template in pure programmatic way? I am a little bit freaky about creating interfaces in that way and not shilled enough yet to do it by myself. I would really appreciate your help…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Upgrade in Utility App from SDK 2.2.1 to SDK 3.0 at Web Builders.

meta

%d bloggers like this: