UINavigationController for IOS development (7)

Source: Internet
Author: User

1 Preface
UINavigationController enables the App to switch from an attempt controller to another one. It is very common in development. Today, let's take a look at this control.

2 UINavigation Introduction
Delegate code

. H file:


[Plain]
# Import <UIKit/UIKit. h>
# Import "ZYRootViewController. h"
 
@ Interface ZYAppDelegate: UIResponder <UIApplicationDelegate>
 
@ Property (strong, nonatomic) UIWindow * window;
@ Property (nonatomic, strong) ZYRootViewController * zYRootViewController;
@ Property (nonatomic, strong) UINavigationController * navigationController;
 
@ End

# Import <UIKit/UIKit. h>
# Import "ZYRootViewController. h"

@ Interface ZYAppDelegate: UIResponder <UIApplicationDelegate>

@ Property (strong, nonatomic) UIWindow * window;
@ Property (nonatomic, strong) ZYRootViewController * zYRootViewController;
@ Property (nonatomic, strong) UINavigationController * navigationController;

@ End. m file:

 

[Plain]
@ Synthesize navigationController;
@ Synthesize zYRootViewController;
 
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
{
Self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen] bounds];
// Override point for customization after application launch.
Self. window. backgroundColor = [UIColor whiteColor];
[Self. window makeKeyAndVisible];
Self. zYRootViewController = [[ZYRootViewController alloc] initWithNibName: nil bundle: nil];
// Instantiate the navigation bar
Self. navigationController = [[UINavigationController alloc] initWithRootViewController: self. zYRootViewController];
// Add a navigation bar to the current view
Self. window. rootViewController = self. navigationController;
// [Self. window addSubview: self. navigationController. view];
Return YES;
}

@ Synthesize navigationController;
@ Synthesize zYRootViewController;

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
{
Self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen] bounds];
// Override point for customization after application launch.
Self. window. backgroundColor = [UIColor whiteColor];
[Self. window makeKeyAndVisible];
Self. zYRootViewController = [[ZYRootViewController alloc] initWithNibName: nil bundle: nil];
// Instantiate the navigation bar
Self. navigationController = [[UINavigationController alloc] initWithRootViewController: self. zYRootViewController];
// Add a navigation bar to the current view
Self. window. rootViewController = self. navigationController;
// [Self. window addSubview: self. navigationController. view];
Return YES;
}


ZYRootViewController code


. M file:


[Plain]
-(Void) viewDidLoad
{
[Super viewDidLoad];
// Do any additional setup after loading the view.
Self. title = @ "First"; // set the title
[Self defined mselector: @ selector (pushSecondController) withObject: nil afterDelay: 3.0f]; // call the pushSecondController method 3 seconds later
}
 
-(Void) pushSecondController {
ZYSecondViewController * zYSecondViewController = [[ZYSecondViewController alloc] initWithNibName: nil bundle: nil];
[Self. navigationController pushViewController: zYSecondViewController animated: YES]; // push zYSecondViewController View to the navigation bar Stack
}

-(Void) viewDidLoad
{
[Super viewDidLoad];
// Do any additional setup after loading the view.
Self. title = @ "First"; // set the title
[Self defined mselector: @ selector (pushSecondController) withObject: nil afterDelay: 3.0f]; // call the pushSecondController method 3 seconds later
}

-(Void) pushSecondController {
ZYSecondViewController * zYSecondViewController = [[ZYSecondViewController alloc] initWithNibName: nil bundle: nil];
[Self. navigationController pushViewController: zYSecondViewController animated: YES]; // push zYSecondViewController View to the navigation bar Stack
} ZYSecondViewController code


. M file:


[Plain]
-(Void) viewDidLoad
{
[Super viewDidLoad];
Self. title = @ "Second ";
// Do any additional setup after loading the view.
[Self defined mselector: @ selector (goBack) withObject: nil afterDelay: 3.0f]; // call the goBack method 3 seconds later
}
 
-(Void) goBack {
[Self. navigationController popViewControllerAnimated: YES]; // bring your own view to the Navigation Pane stack.
}

-(Void) viewDidLoad
{
[Super viewDidLoad];
Self. title = @ "Second ";
// Do any additional setup after loading the view.
[Self defined mselector: @ selector (goBack) withObject: nil afterDelay: 3.0f]; // call the goBack method 3 seconds later
}

-(Void) goBack {
[Self. navigationController popViewControllerAnimated: YES]; // bring your own view to the Navigation Pane stack.
} Running result:

Initial Effect

 



Jump to the second view 3 seconds later:

 
 


This view will pop up three seconds later, showing the initial view:

 

 
 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.