Create a multi-page, uinavigationcontroller-based jump IOS Application

Source: Internet
Author: User

From android to iOS development, I am not used to it at the beginning. I always like to use the android idea to use the controls on iOS. The result is hitting the wall everywhere, and I keep hitting it, now, if you are idle, just write something simple at the beginning.ProgramTo deepen your understanding of iOS development.

1. First create an empty IOS Project (I use the arc mechanism by default, so the followingCode). The project directory is as follows:

2. Modify vsappdelegate. H, add a uinavigationcontroller type attribute navicontroller, and add the attribute get/set method declaration to vsappdelegate. C. In this example, we only modify

(Bool) Application :(Uiapplication*) Application didfinishlaunchingwitexceptions :(Nsdictionary*) Launchoptions method. You can manually delete other methods and add them when using them. Modify the method below to add navicontroller to the program, before that, you need to create a program startup screen. In this example, vsloginviewcontroller is used as the rootviewcontroller when initializing navicontroller, the specific implementation code is as follows:

-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {self. window = [[uiwindow alloc] initwithframe: [uiscreen mainscreen] bounds]; vsloginviewcontroller * loginview = [[vsloginviewcontroller alloc] handler: @ "vsloginviewcontroller" Bundle: Nil]; self. navicontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller: loginview]; self. window. rootviewcontroller = self. navicontroller; self. window. backgroundcolor = [uicolor whitecolor]; [self. window makekeyandvisible]; return yes ;}

The startup screen is as follows:

Maybe you may wonder why your program has a navigation bar, but I don't have one. The reason is very simple: I am in vsloginviewcontroller (Void) Viewwillappear :(Bool) The imated method hides the navigation bar. The Code is as follows:

-(Void) viewwillappear :( bool) animated {[self. navigationcontroller setnavigationbarhidden: Yes animated: Yes]; [Super viewwillappear: animated];}

Before performing the jump logic, we also need to set the title of the rollback button of the navigation bar on the next page. Yes, the title of the rollback button on the next page is set on this page, there are two methods: 1. set the title attribute of the current screen; 2. modify the back button of the navigation bar of the next page. This setting is implemented in the init method of viewcontroller. The Code is as follows:

 
-(ID) initwithnibname :( nsstring *) nibnameornil bundle :( nsbundle *) attributes {self = [Super initwithnibname: nibnameornil Bundle: nibbundleornil]; If (Self) {uibarbuttonitem * backitem = [[uibarbuttonitem alloc] init]; backitem. title = @ "logout"; self. navigationitem. backbarbuttonitem = backitem; // self. title = @ "logout";} return self ;}

3. The following describes the page Jump logic. First, declare a method login in vsloginviewcontroller. H, bind the method to the XIB button, and then implement the login method. The Code is as follows:

-(Void) login :( ID) sender {vsmainviewcontroller * mainviewcontroller = [[vsmainviewcontroller alloc] initwithnibname: @ "vsmainviewcontroller" Bundle: Nil]; [self. navigationcontroller pushviewcontroller: mainviewcontroller animated: Yes];}

After setting, click this button to jump to the next page:

The navigation bar is displayed, which is also set in the viewwillappear method. If it is not set, the previous navigation bar setting is used by default.

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.