Sunday, June 9, 2013

UINavigationController pushViewController animated example in Objective C (iOS).


UINavigationController pushViewController animated

Pushes a view controller onto the receiver’s stack and updates the display.

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

Parameters of [UINavigationController pushViewController animated]
viewController
The view controller that is pushed onto the stack. This object cannot be an instance of tab bar controller and it must not already be on the navigation stack.
animated
Specify YES to animate the transition or NO if you do not want the transition to be animated. You might specify NO if you are setting up the navigation controller at launch time.

Discussion of [UINavigationController pushViewController animated]
The object in the viewController parameter becomes the top view controller on the navigation stack. Pushing a view controller results in the display of the view it manages. How that view is displayed is determined by the animated parameter. If the animated parameter is YES, the view is animated into position; otherwise, the view is simply displayed in place. The view is automatically resized to fit between the navigation bar and toolbar (if present) before it is displayed.[UINavigationController pushViewController animated]

In addition to displaying the view associated with the new view controller at the top of the stack, this method also updates the navigation bar and tool bar accordingly. In iOS 3.0 and later, the contents of the built-in navigation toolbar are updated to reflect the toolbar items of the new view controller. For information on how the navigation bar is updated, see “Updating the Navigation Bar.”

Important: In iOS 2.2 and later, if the object in the viewController parameter is already on the navigation stack, this method throws an exception. In earlier versions of iOS, the method simply does nothing.
UINavigationController pushViewController animated example.
- (void) viewDidAppear
{   
    [self performSelector:@selector(loginCheck:) withObject:nil afterDelay:0.5];
}   
- (void) loginCheck:(id)sender
{
    LoginViewController * lvc = [[LoginViewController alloc] init];
    //lvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [lvc setDelegate:self];
    //[self presentModalViewController:lvc animated:YES];  
    [self.navigationController pushViewController:lvc animated:YES];  
}

Example of [UINavigationController pushViewController animated].
- (void)viewDidLoad {
[super viewDidLoad];
    UINavigationController *navigationController
navigationController = [[UINavigationController alloc] init];
[self.view addSubview:navigationController.view];  

switch (whichViewController) {
    case 1:
        viewController = [[xxxx alloc] init];          
        break;
    case 2:
        viewController = [[xxx1 alloc] init];          
        break;
    default:
        break;
}

[navigationController pushViewController:viewController animated:NO];
[viewController release];
}

UINavigationController pushViewController animated example.
- (void)ShowPageWithIMDevicePage:(id<IMDevicePage>)page {
    YourDelegate* delegate = (YourDelegate*)[[UIApplication sharedApplication] delegate];
    IPhonePage* pageVC = (IPhonePage*)page;
    [delegate.navigationController pushViewController:pageVC animated:YES];
}

End of UINavigationController pushViewController animated example article.