In the iOS navigation bar, how does one use UINavigationController and switch between pages,

Source: Internet
Author: User

In the iOS navigation bar, how does one use UINavigationController and switch between pages,
Use of the navigation bar

NavigationController manages the switch between the Bar at the top of the screen and different uiviewcontrollers.

You can drag the Navigation Controller to the storyboard to generate a Navigation bar. This navigation bar displays the return button, the name of the current page, and so on.

After you set the title of ViewController, the navigation bar displays the title of the current page. For example

- (void)viewDidLoad {    [super viewDidLoad];    self.title = @"Page1";}

Set the page title controlled by ViewController to Page1 ".

Page switching method 1

You can use the drag and drop button method to generate a page switching program. You only need to right-click a button on the storyboard and drag it to another page. You can select several switching Methods: show, show detail, present modally, present as popover and Custom. To generate a return button in the navigation bar, select show mode.

Method 2

You can use the code to complete page switching. First, you need to set a Storyboard ID for the target page to which you will go, for example, set page2ViewController, and then set button events, I am lazy and drag the button email to the code area to generate a function shell named GoToPage2. I set the button on the first page to jump to the second page,You need to import the header file of the UIViewController variable on the second page in ViewController. m.And then add two lines of code to the button event function. The function is as follows:

-(IBAction) GoToPage2 :( id) sender {Page2ViewController * page2 = [self. storyboard instantiateViewControllerWithIdentifier: @ "page2ViewController"]; // sets the jump page [self. navigationController pushViewController: page2 animated: YES]; // sets the Redirect mode}

This method generates a return button in the navigation bar after the jump.

Related Article

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.