460 likes | 753 Views
מגישה: רננה דואני סמסטר ב' תש"ע מרצה: ד"ר יצחק אביב. iPhone Application. המחלקה להנדסת תוכנה, מכללת אפקה. iPhone Application. iPhone introduction iPhone Application-Introduction iPhone - Hello World Application Open new Project Create files Debug Compile
E N D
מגישה: רננה דואני סמסטר ב' תש"ע מרצה: ד"ר יצחק אביב iPhone Application המחלקה להנדסת תוכנה, מכללת אפקה
iPhone Application • iPhone introduction • iPhone Application-Introduction • iPhone- Hello World Application • Open new Project • Create files • Debug • Compile • iPhone- Password Generator • The code
iPhone - Introduction • The iPhone is extremely thin , The display area is a 3.5-inch wide screen multi-touch interface with unusually high resulotion. It is compatible with Microsoft's Windows operating systems, including Vista. It also comes preloaded with a suite of media management software and communications software, including iTunes, the Safari Web browser and iPhoto. The user interface is built around the device's multi-touch screen, including a virtual keybord in lieu of a physical keyboard. Third-party applications are available from the App store. The iPhone 3GS has improved performance, a camera with higher resolution and video capability, voice control , and support for 7.2 Mbps HSDPA downloading.
iPhone-Application Introduction • In version 3.0, the iPhone home screen contains these default applications: • Messages, Calendar, Photos ,Camera ,YouTube ,Stocks ,Weather, Clock, Calculator , Voice Memos, Notes, Settings , iTunes , Apps Store, , Compass Contacts , and the Nike + iPod that interfaces with the optional Nike + iPod sensor. • Four other applications delineate the iPhone's main purposes: Phone, Mail , Safari and iPod.
Creating iPhone Application Creating Application ID Making Your Device Available for Development
Steps To Create Application • Creating an App ID • To install your application onto your iPhone touch, you will need to create an App ID. • The App ID is also used as part of the mobile provisioning profile. • Go to the App IDs section of the iPhone Developer Program Portal, select the Manage tab, and click on New App ID. Enter a name for your App ID. • For the Bundle Seed ID select Generate New. • Finally, enter a Bundle Identifier. • Making Your Device Available for Development • Return to Xcode and click Window→Organizer from the menu. Select your development device from the lefthand pane and click Use for Development. • Once you’ve installed the profiles, you can verify that Xcode has correctly stored them by opening the Library folder in your home directory and looking in MobileDevice/ Provisioning Profiles. The next time you sync your development device with, the mobile provisioning profile will be installed onto it. • You can verify that the profile has been installed by going to Settings→General→Profile on your iPhone touch and checking that the profile has been correctly installed and verified. • If Xcode has managed to connect to the device, and it is correctly enabled for development, the status light next to the listing on the lefthand pane will be green. You’ll also see your mobile provisioning profile listed in the center box in the main pane.
Here we can see that the configuration successes • Overview of an iPhone application: Main.h & Main.m AppDelegate.h & AppDelegate.m AppController.h & AppController.m
Creating My Application • In an Info.plist file, you specify where the application’s executable (CFBundleExecutable,“Executable file”) can be found, the text that appears under the application icon (CFBundleDisplayName,“Bundle display name”), and the application’s unique identifier (CFBundleIdentifier,“Bundle identifier). • The icon.png image and Default.png are two key image files. Icon.png acts as your application’s icon, the image used to represent the application on the SpringBoard home screen. Default.png (also known as your “launch image”) provides the splash screen displayed during application launch. The official application icon size is 57-by-57 pixels. example of Apps Icon
New Project • Launch Xcode by double-clicking its icon (it’s located in the /Developer/Applications folder on your hard drive). Click “Create a new Xcode project” in the Xcode welcome window, and then click Application under the iPhone OS section on the left side of the screen. Next, click the View-based. • Application template and click Choose. • When prompted, name your new project HelloWorld. Make sure you don’t put a space between Hello and World, as this can sometimes confuse Xcode.
HelloWorld Application HelloWorld.h: #import <UIKit/UIKit.h> // load the necessary library for show @class HelloWorldViewController; //create class @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> { //UIApplication- getting the message from //UIApplicationDelegate - implements from UIWindow *window; HelloWorldViewController *viewController; //show the wanted text } @property (nonatomic, retain) IBOutletUIWindow *window; @property (nonatomic, retain) IBOutlet // This is a place marker to tell Xcode that this object in our code can be //connected to a UI component in Interface Builder HelloWorldViewController *viewController; @end
HelloWorld.m #import "HelloWorldAppDelegate.h" // The header files are imported with the class declarations for both the HelloWorldApp Delegate and the // HelloWorldViewController classes. #import "HelloWorldViewController.h" @implementation HelloWorldAppDelegate // This is the beginning of the declaration of the Hello World application delegate class. @synthesize window; @synthesize viewController; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch [window addSubview:viewController.view]; //Here, I add the view managed by the viewController object as a subview of the main window. [window makeKeyAndVisible]; //This makes the window visible using the makeKeyAndVisible method. } - (void)dealloc { [viewController release]; [window release]; [super dealloc]; } @end //This is the end of the declaration of the Hello World application delegate class.
HelloWorldViewController.h : #import <UIKit/UIKit.h> @interface HelloWorldViewController : UIViewController { } @end
HelloWorldViewController.m : #import "HelloWorldViewController.h" @implementation HelloWorldViewController // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } // Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Releases any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Releases any retained subviews of the main view. } - (void)dealloc { [super dealloc]; } @end
Running Application On iPhone Select View-based Application and click Choose When Xcode prompts you to Save As, name the project HelloWorld and save it to your Desktop with Save. A new HelloWorld Xcode project window opens. Xcode > Preferences select the General pane, and choose the layout from the pop-up.
a pop-up that offers typical project functionality like adding new files and Reveal in Finder to locate those files on your Macintosh a pop-up sets your targets and configuration moves you between the project overview and the visual debugger Build and Go button Info button Groups and Files column J-Detail K- Project Find L- SCM Results M-Build Products folder HelloWorld.app application Targets item resize bar default selection for the project window preview of whichever element has been selected on the top
Run Project: • double-click the View object • open the library by choosing Tools > Library • double-click the label in the middle pane. This automatically adds that item to your view. • double-click the label and change the word from "Label" to what ever we want. • File > Save. Run Application: • Choose Project > Set Active SDK > iPhone Simulator (3.0) • Click Build and Go in the main project window.
Another way for writing Application by one file: #import <UIKit/UIKit.h> @interface HelloWorldViewController : UIViewController // It starts in main.m by establishing the autorelease pool and calling UIApplicationMain. From there, control passes to the //application delegate, which is specified as the last argument of the call.This is a critical point for building a non-Interface //Builder //project. //The delegate, receiving an application did launch message, builds a new window and creates a new //instance of a custom view //controller @end @implementation HelloWorldViewController //It adds that controller’s view to the window. - (void)loadView { UIView *contentView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]]; // The view controller waits for a request to load its view and when that request comes in, it runs loadView, which builds the view //and adds the Hello World text. This sample starts by creating a new view and telling it to //fill the full space available to the //application. It then sets the background color, in this case to light gray. contentView.backgroundColor = [UIColor lightGrayColor]; // the sample builds a new instance of the UILabel class. Each of the label properties is set by hand. UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 30.0f)]; label.text = @"Hello World"; label.center = contentView.center; label.textAlignment = UITextAlignmentCenter; label.backgroundColor = [UIColor clearColor]; [contentView addSubview:label]; [label release]; self.view = contentView; [contentView release]; } @end
// Building views by hand means using this loadView method to set up the primary view and its children. @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> @end @implementation HelloWorldAppDelegate - (void)applicationDidFinishLaunching:(UIApplication *)application { UIWindow *window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; HelloWorldViewController *hwvc; hwvc = [[HelloWorldViewController alloc] init]; [window addSubview:hwvc.view]; [window makeKeyAndVisible]; } @end int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate"); [pool release]; return retVal; } /* This code does not provide a dealloc method for the application delegate as it never gets called. The iPhone OS recovers all application memory during the application tear-down. Technically, the view controller leaks. In practice, this isn’t a problem. */
Debugging Make sure the breakpoint is dark blue and that the button at the top of the debugger says “Deactivate” (which means that the breakpoint is active), and click Build and Go to run the program in the simulator. The program automatically stops when it hits the breakpoint.
To test console logging, add a NSLog(@”Hello World!”); line to your code; place it after the contentView release. Compile and run the application in the simulator. The log message appears in the console pane. The console keeps a running log of messages regardless of how many times you have tested your application. You can manually clear the log as needed. Log Place in: Tethered iPhones automatically send their NSLog output to the Xcode organizer (Window > Organizer > Device Name > Console). For example, when run on an iPhone, that NSLog command displays like the following. It shows the date and time, the program name and the NSLog output (in this case,“Hello World!”).
iPhone- Password Generator For this application we will need 12 files: FileSideview.h\m FileSideViewController.h\m Mainview.h\m MainviewController.h\m PasswordGenAppDelegate.h\m RootViewController.h\m
FileSideview.h: #import <UIKit/UIKit.h> @interface FlipsideView : UIView { } //this is like void , Interface Builder will also make this method available to itself so we //can choose which event will call this method. - (IBAction)openLink; @end
FlipsideView.m : #import "FlipsideView.h" @implementation FlipsideView //The function that we defined in the .h file - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code } return self; } - (void)drawRect:(CGRect)rect { // Drawing code } - (void)dealloc { [super dealloc]; } //here is the file that we declared in the .h file -(IBAction) openLink { // open in Safari //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.apple.com/"]]; //place where we can see other applications [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=287545019&mt=8"]]; } @end
//coordinator for the UI of iPhone FlipsideViewController.h : #import <UIKit/UIKit.h> //sets the touch @interface FlipsideViewController : UIViewController { } @end
//the implementation of the .h file FlipsideViewController.m : #import "FlipsideViewController.h" @implementation FlipsideViewController - (void)viewDidLoad { //self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor]; self.view.backgroundColor = [UIColor blackColor]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview // Release anything that's not essential, such as cached data } - (void)dealloc { [super dealloc]; } @end
Mainview.h : #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> //the application as its displayed on the screen @interface MainView : UIView { IBOutlet UITextField *passwordLength; IBOutlet UITextField *emailAddress; IBOutlet UISwitch *includeLowerCase; IBOutlet UISwitch *includeNumbers; IBOutlet UISwitch *includePunctuation; IBOutlet UISwitch *includeUpperCase; IBOutlet UISwitch *showPhonetics; IBOutlet UITextField *password; IBOutlet UITextView *phoneticPassword; IBOutlet UIButton *emailPasswordButton; } //Marking your properties nonatomic does speed up access, but you might run into //problems should two competing threads attempt to modify the same property at //once . Atomic properties, with their lock/unlock behavior, ensure that an object update //completes from start to finish before that property is released to another read or change. //By writing like this we ensure that when we try to change //the *emaliAddress for example, only the first function that accesses the variable will be able to use it and it will be //locked. After it finishes to change or use this variable it will return the variable state to unlock. @property (nonatomic, retain) UITextField *emailAddress; @property (nonatomic, retain) UITextView *phoneticPassword; @property (nonatomic, retain) UITextField *passwordLength; @property (nonatomic, retain) UIButton *emailPasswordButton; - (IBAction)setPasssword; - (IBAction)resignResponder; - (IBAction)emailPassword; @end
Mainview.m : #import "MainView.h" //defines const variable #define RANDOM_SEED() srandom(time(NULL)) #define RANDOM_INT(__MIN__, __MAX__) ((__MIN__) + random() % ((__MAX__+1) - (__MIN__))) @implementation MainView //builds routines that manage the retained property in Mainview.h @synthesize phoneticPassword; @synthesize passwordLength; @synthesize emailPasswordButton; @synthesize emailAddress; - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { } return self; } //sets the variables - (IBAction)setPasssword { [UIViewbeginAnimations:nilcontext:NULL]; [UIView setAnimationDuration:1]; [password setAlpha:0.0]; [phoneticPassword setAlpha:0.0]; [emailPasswordButton setAlpha:0.0]; [UIViewcommitAnimations]; [UIViewbeginAnimations:nilcontext:NULL]; [UIView setAnimationDuration:1]; [password setAlpha:0.85]; if(showPhonetics.on) {[phoneticPassword setAlpha:0.85];} [emailPasswordButton setAlpha:0.85]; [UIViewcommitAnimations];
//array of chars that can be legal to get/set • NSArray *keys = [NSArray arrayWithObjects: • @"a", @"b", @"c", @"d", @"e“, @"f", @"g", @"h", @"i", @"j“, @"k", @"l", @"m", @"n", @"o“,@"p", @"q", @"r", @"s", @"t“,@"u", @"v", @"w", @"x", @"y", @"z“,@"A", @"B", @"C", @"D", @"E“,@"F", @"G", @"H", @"I", @"J“,@"K", @"L", @"M", @"N", @"O“,@"P", @"Q", @"R", @"S", @"T“,@"U", @"V", @"W", @"X", @"Y", @"Z“,@"0", @"1", @"2", @"3", @"4“,@"5", @"6", @"7", @"8", @"9“,@"~", @"!", @"?", @"#", @"%“,@"^", @"&", @"*", @"(", @")“,nil]; • //array of signs that can be legal to get/set • NSArray *objects = [NSArray arrayWithObjects: • @"alpha", @"bravo", @"charlie", @"delta", @"echo", • @"foxtrot", @"golf", @"hotel", @"india", @"juliet", • @"kilo", @"lima", @"mike", @"november", @"oscar", • @"papa", @"quebec", @"romeo", @"sierra", @"tango", • @"uniform", @"victor", @"whiskey", @"xray", @"yankee", @"zulu", • @"ALPHA", @"BRAVO", @"CHARLIE", @"DELTA", @"ECHO", • @"FOXTROT", @"GOLF", @"HOTEL", @"INDIA", @"JULIET", • @"KILO", @"LIMA", @"MIKE", @"NOVEMBER", @"OSCAR", • @"PAPA", @"QUEBEC", @"ROMEO", @"SIERRA", @"TANGO", • @"UNIFORM", @"VICTOR", @"WHISKEY", @"XRAY", @"YANKEE", @"ZULU", • @"Zero", @"One", @"Two", @"Three", @"Four", • @"Five", @"Six", @"Seven", @"Eight", @"Nine", • @"Tilda", @"Exclamation Point", @"Question Mark", @"Pound Sign", @"Percent Sign", • @"Carrot Sign", @"Ampersand", @"Asterick", @"Left Parenthesis", @"Right Parenthesis“,nil];
//defines the text that can be in the password NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; NSInteger iPassswordLength = [passwordLength.text intValue]; BOOL bShowPhonetics = showPhonetics.on; BOOL bIncludeLowerCase = includeLowerCase.on; BOOL bIncludeUpperCase = includeUpperCase.on; BOOL bIncludeNumbers = includeNumbers.on; BOOL bIncludePunctuation = includePunctuation.on; //the pattern of the password NSString* passwordText = @""; NSString* phoneticText = @""; NSString* lowercaseChars = @"abcdefghijklmnopqrstuvwxyz"; NSString* uppercaseChars = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; NSString* numbersChars = @"0123456789"; NSString* punctuationChars = @"~!?#%^&*()"; //random number RANDOM_SEED(); if(!bIncludeLowerCase && !bIncludeUpperCase && !bIncludeNumbers && !bIncludePunctuation) { //alerts that all required parameters are not set UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"PasswordGen" message: @"No password character set selected." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; [alert release]; return; }
//check if input is legal NSString* passwordChars = @""; if(bIncludeLowerCase) passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, lowercaseChars]; if(bIncludeUpperCase) passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, uppercaseChars]; if(bIncludeNumbers) passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, numbersChars]; if(bIncludePunctuation) passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, punctuationChars]; //get a random num for(NSInteger i=0; i<iPassswordLength; i++) { //index= random number; FROM=0; TO=[passwordChars length]-1 int index = RANDOM_INT(0, [passwordChars length]-1); NSRange range = NSMakeRange(index, 1); NSString *passwordChar = [passwordChars substringWithRange:range]; passwordText = [NSString stringWithFormat:@"%@%@", passwordText, passwordChar]; NSLog(passwordChar); if(i>0) phoneticText = [NSString stringWithFormat:@"%@, %@", phoneticText, [dictionary valueForKey:passwordChar]]; else phoneticText = [dictionary valueForKey:passwordChar]; } password.text = @"";
password.text = passwordText; phoneticPassword.text = @""; if(bShowPhonetics) phoneticPassword.text = phoneticText; } -(IBAction) resignResponder { [password resignFirstResponder]; [passwordLength resignFirstResponder]; } //initialized text field - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == password) { [password resignFirstResponder]; } if (textField == passwordLength) { [passwordLength resignFirstResponder]; } return YES; } //send the password to some mail if we wand -(IBAction) emailPassword { NSString *urlString = @"mailto:?subject=Password%20Generator&body="; urlString = [urlString stringByAppendingString:@"Password:%20"]; urlString = [urlString stringByAppendingString:password.text]; if(showPhonetics.on) { urlString = [urlString stringByAppendingString:@"%20Phonetic:%20"]; urlString = [urlString stringByAppendingString:[phoneticPassword.text stringByReplacingOccurrencesOfString:@" " withString:@"%20"]]; } NSURL* mailURL = [NSURL URLWithString: urlString]; [[UIApplication sharedApplication] openURL: mailURL]; } @end
MainViewController.h : //the buttons that will be present on screen #import <UIKit/UIKit.h> @interface MainViewController : UIViewController { IBOutlet UIButton *createPassword; IBOutlet UIButton *emailPassword; } @property (nonatomic, retain) UIButton *createPassword; @property (nonatomic, retain) UIButton *emailPassword; @end
MainViewController.m : #import "MainViewController.h" #import "MainView.h" @implementation MainViewController @synthesize createPassword; @synthesize emailPassword; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNilbundle:nibBundleOrNil]) { } return self; } //the design of the button on the screen - (void)viewDidLoad { UIImage *buttonBackground = [[UIImageimageNamed:@"blueButton.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:12.0 ]; [createPasswordsetBackgroundImage:buttonBackgroundforState:UIControlStateNormal]; [emailPasswordsetBackgroundImage:buttonBackgroundforState:UIControlStateNormal]; [createPasswordsetTitleColor:[UIColorwhiteColor] forState:UIControlStateNormal]; [emailPasswordsetTitleColor:[UIColorwhiteColor] forState:UIControlStateNormal]; UIImage *buttonBackgroundSel = [[UIImageimageNamed:@"whiteButton.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:12.0 ];
[createPassword setBackgroundImage:buttonBackgroundSel forState:UIControlStateHighlighted]; [createPassword setBackgroundImage:buttonBackgroundSel forState:UIControlStateSelected]; [emailPassword setBackgroundImage:buttonBackgroundSel forState:UIControlStateHighlighted]; [emailPassword setBackgroundImage:buttonBackgroundSel forState:UIControlStateSelected]; [createPassword setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted]; [createPassword setTitleColor:[UIColor blackColor] forState:UIControlStateSelected]; [emailPassword setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted]; [emailPassword setTitleColor:[UIColor blackColor] forState:UIControlStateSelected]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview // Release anything that's not essential, such as cached data }
- (void)dealloc { [emailPassword release]; [createPassword release]; [super dealloc]; } @end
PasswordGenAppDelegate.h : #import <UIKit/UIKit.h> @class RootViewController; //delegate to rootViewController file that start the apps @interface PasswordGenAppDelegate : NSObject <UIApplicationDelegate> { IBOutlet UIWindow *window; IBOutlet RootViewController *rootViewController; } @property (nonatomic, retain) UIWindow *window; @property (nonatomic, retain) RootViewController *rootViewController; @end
PasswordGenAppDelegate.m : //implement the .h file #import "PasswordGenAppDelegate.h" #import "RootViewController.h" @implementation PasswordGenAppDelegate @synthesize window; @synthesize rootViewController; - (void)applicationDidFinishLaunching:(UIApplication *)application { [window addSubview:[rootViewController view]]; [window makeKeyAndVisible]; } - (void)dealloc { [rootViewController release]; [window release]; [super dealloc]; } @end
RootViewController.h : //define the apps buttons #import <UIKit/UIKit.h> @class MainViewController; @class FlipsideViewController; @interface RootViewController : UIViewController { IBOutlet UIButton *infoButton; MainViewController *mainViewController; FlipsideViewController *flipsideViewController; UINavigationBar *flipsideNavigationBar; } @property (nonatomic, retain) UIButton *infoButton; @property (nonatomic, retain) MainViewController *mainViewController; @property (nonatomic, retain) UINavigationBar *flipsideNavigationBar; @property (nonatomic, retain) FlipsideViewController *flipsideViewController; - (IBAction)toggleView; @end
RootViewController.m : #import "RootViewController.h" #import "MainViewController.h" #import "FlipsideViewController.h" @implementation RootViewController @synthesize infoButton; @synthesize flipsideNavigationBar; @synthesize mainViewController; @synthesize flipsideViewController; //sets the start of the RootViewController - (void)viewDidLoad { MainViewController *viewController = [[MainViewControlleralloc] initWithNibName:@"MainView" bundle:nil]; self.mainViewController = viewController; [viewController release]; [self.viewinsertSubview:mainViewController.viewbelowSubview:infoButton]; } - (void)loadFlipsideViewController { FlipsideViewController *viewController = [[FlipsideViewControlleralloc] initWithNibName:@"FlipsideView" bundle:nil]; self.flipsideViewController = viewController; [viewController release];
// Set up the navigation bar UINavigationBar *aNavigationBar = [[UINavigationBaralloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)]; aNavigationBar.barStyle = UIBarStyleBlackOpaque; self.flipsideNavigationBar = aNavigationBar; [aNavigationBar release]; UIBarButtonItem *buttonItem = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDonetarget:self action:@selector(toggleView)]; UINavigationItem *navigationItem = [[UINavigationItemalloc] initWithTitle:@"Password Generator"]; navigationItem.rightBarButtonItem = buttonItem; [flipsideNavigationBarpushNavigationItem:navigationItemanimated:NO]; [navigationItem release]; [buttonItem release]; } - (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; [UIViewbeginAnimations:nilcontext:NULL]; [UIView setAnimationDuration:1]; [UIViewsetAnimationTransition:([mainViewsuperview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.viewcache: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]; }
-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview // Release anything that's not essential, such as cached data } - (void)dealloc { [infoButton release]; [flipsideNavigationBar release]; [mainViewController release]; [flipsideViewController release]; [super dealloc]; } @end
Application Result The constancy to fill for the wanted password The Password that we get after running this application Press this Button will create password Password in word There is an option to send this password by mail
Writing HelloWorld Apps Movie Writing HelloWorld Application- Xcode