Created
April 22, 2010 00:40
-
-
Save tilomitra/374647 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The first example is adding a subview to your MainWindow nib so that it loads a nib from another view controller. | |
//The following code goes in the AppDelegate.m under the following method | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
// Override point for customization after application launch | |
[window addSubview:switchViewController.view]; //replace switchViewController with your own viewController | |
[window makeKeyAndVisible]; | |
return YES; | |
} | |
//The second example shows how to add subviews to a viewController | |
//This would go in the view controller you are adding subviews to. | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
//In this case, BlueViewController is a viewController that is being called in this viewController (switchViewController) | |
BlueViewController *blueController = [[BlueViewController alloc] initWithNibName:@"BlueViewController" bundle:nil]; | |
self.blueViewController = blueController; | |
[self.view insertSubview:blueController.view atIndex:0]; //index 0 determines zindex. | |
[blueController release]; | |
} | |
//This example shows how to remove views (like the one above) | |
[yellowViewController.view removeFromSuperview]; | |
//You can also check to see if the view of a given viewController is present using the following: | |
if (self.blueViewController.view.superview == nil) { | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test" message:@"clicked" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; | |
[alert show]; | |
[alert release]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(IBAction)switchViews:(id)sender { | |
//Create the second view (the one that is not showing) | |
if (self.yellowViewController == nil) { | |
//Supply your own nib name here ofcourse... | |
YellowViewController *yellowController = [[YellowViewController alloc] initWithNibName:@"YellowViewController" bundle:nil]; | |
self.yellowViewController = yellowController; | |
[yellowController release]; | |
} | |
[UIView beginAnimations:@"View Flip" context:nil]; | |
[UIView setAnimationDuration:1.25]; | |
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; | |
//The if/else below looks at which view is showing, so that it knows what to hide and what to show | |
//The blueviewcontroller is nil, which means the yellow one must be showing.. | |
if (self.blueViewController.view.superview == nil) { | |
/* | |
* Instead of FlipFromRight, we could have used: | |
* UIViewAnimationTransitionFlipFromRight | |
* UIViewAnimationTransitionFlipFromLeft | |
* UIViewAnimationTransitionCurlUp | |
* UIViewAnimationTransitionCurlDown | |
*/ | |
//Always have cache:YES unless you want the view look to change during the animation (like it does in Classics page flip) | |
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; | |
[blueViewController viewWillAppear:YES]; | |
[yellowViewController viewWillDisappear:YES]; | |
[yellowViewController.view removeFromSuperview]; | |
[self.view insertSubview:blueViewController.view atIndex:0]; | |
[blueViewController viewDidAppear:YES]; | |
[yellowViewController viewDidDisappear:YES]; | |
} | |
//The blue one is showing | |
else { | |
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; | |
[yellowViewController viewWillAppear:YES]; | |
[blueViewController viewWillDisappear:YES]; | |
[blueViewController.view removeFromSuperview]; | |
[self.view insertSubview:yellowViewController.view atIndex:0]; | |
[yellowViewController viewDidAppear:YES]; | |
[blueViewController viewDidDisappear:YES]; | |
} | |
//Need this!! | |
[UIView commitAnimations]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the Gregorian calendar | |
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; | |
// Get the date | |
NSDate* now = [NSDate date]; | |
// Get the hours, minutes, seconds | |
NSDateComponents* nowHour = [cal components:NSHourCalendarUnit fromDate:now]; | |
NSDateComponents* nowMinute = [cal components:NSMinuteCalendarUnit fromDate:now]; | |
NSDateComponents* nowSecond = [cal components:NSSecondCalendarUnit fromDate:now]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// just some date | |
NSDate *fooDate = [NSDate date]; | |
// setting units we would like to use in future | |
unsigned units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit; | |
// creating NSCalendar object | |
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; | |
// extracting components from date | |
NSDateComponents *components = [calendar components:units fromDate:fooDate]; | |
// getting our fooDate components. On at the time. Oh, and they're integers! | |
[components year]; | |
[components month]; | |
[components day]; | |
[components weekday]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is your modal view controller | |
addProjectViewController = [[AddProjectViewController alloc] initWithNibName:@"AddProjectViewController" bundle:nil]; | |
UINavigationController *modalNavigationController = [[UINavigationController alloc] initWithRootViewController:addProjectViewController]; | |
//Set up Modal styles | |
modalNavigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; | |
modalNavigationController.modalPresentationStyle = UIModalPresentationFormSheet; | |
//self refers to the view controller showing the modal view controller | |
[self presentModalViewController:modalNavigationController animated:YES]; | |
//release controllers from memory | |
[addProjectViewController release]; | |
[modalNavigationController release]; | |
//To Dismiss, go to the Modal View Controller and call: | |
[self dismissModalViewControllerAnimated:YES]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment