iOS Development Tabbaritem&navigationbaritem

Source: Internet
Author: User

Presumably everyone has used, between the page switch is how to make it? Next we use storyboard to simulate the view control pattern with the code.

"工欲善其事, its prerequisite", the following is mainly for the storyboard to carry out our project framework, when necessary, to achieve our page effect with code. The switch between multiple views commonly used in iOS development is roughly Tabbarcontroller, Navigationbarcontroller, and modal windows. The concept of the first contact mode is in contact with the content of the Web front end. The following will be combined with a practical effect to briefly introduce Tabbar and Navigationbar, and then say with our storyboard and pure code how to configure our Navigationbar, The previous blog mentions how to use navigation to achieve the switch between pages, next we want to combine with Tabbarcontroller, to do a anti-view control. The relationship between the view controller below is how to use storyboard to drag out, in the previous blog mentioned, in this small series will not repeat.

The relationship between Viewcontroller is roughly into:

View Relationship Description:

1. When opened, a landing page will appear first, and when the login is successful, it will jump to the tab Bar Controller.

2. In the tab controller, there are three navigation controllers, and clicking on different item jumps to a different navigationcontroller.

3. Each navigation controller also corresponds to some viewcontroller, which can be toggled between the Viewcontroller by a button control Navigationcontroller.

  

1. Landing page of the jump implementation

In the landing viewcontroller to jump to Tabbarcontroller in accordance with the user input information to achieve the jump. In other words, the landing page in storyboard and other pages is not related, we need to use business logic to achieve, the following is the form of modal to switch views. The controls used in the login interface and how the keyboard is retracted are mentioned in the previous blog. The core code to jump to Tabbarcontroller based on user input is as follows:

• 1-(ibaction) Tapbutton: (ID) Sender {     
23NSString * UserName =[self.username text];4NSString * Password =Self.password.text;5Analog Login6 if([userName isequal:password] = = YES &&! [UserName isequal:@""] &&! [Password isequal:@""]) {7 //Get Storyboard8Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@"Main"Bundle:[nsbundle Mainbundle]];9 Ten //obtained by Storyboardid Tabbarviewcontroller OneUiviewcontroller * Mytabbarcontroller = [Storyboard Instantiateviewcontrollerwithidentifier:@"Mytabbarcontroller"]; A - //redirect the interface to our Tabbarviewcontroller -[Self Presentviewcontroller:mytabbarcontroller animated:yes completion:^{ the }]; - } -}

2. How do we associate our new View controller class with our new view controller? In fact, in our storyboard is quite simple, in the storyboard select the view controller that we want to associate, in class to choose our new view controller class. After the correlation we can implement our business logic in the corresponding attempt controller class, the operation is as follows:

3. The switch between the Viewcontroller controlled by navigation is done by the stack, and the switch between the pages is accompanied by the process of the stack or the stack. The next step is to configure Navigatebar for each navigation controller, with only one navigationbar in one navigationcontroller, And in a navigationcontroller under the various viewcontroller have their own navigationbaritem. We can configure our Navigationbar by storyboard in a drag-and-drop manner, or by hand-written code:

(1) Use storyboard to add a button to our navigation bar, drag and drop the button and then configure the relevant properties

(2) How should we add bar Button item to our handwritten code? The code given below is implemented with pure code.

1     //manually add the right button to the Navigationbar2     //new BarButtonItem1, specifying styles, and registering callbacks3Uibarbuttonitem *item1 =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemadd4 target:self5 Action: @selector (Tapbarbutton)];6     //new BarButtonItem2, specifying styles, and registering callbacks7Uibarbuttonitem *item2 =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcamera8 target:self9 Action: @selector (Tapbarbutton)];Ten     //Add a button to the right OneSelf.navigationItem.rightBarButtonItem =item1; A      -     //add two buttons to the right -Self.navigationItem.rightBarButtonItems =@[item1, item2]; the      -     //Add a Barbutton to the left -Self.navigationItem.leftBarButtonItem =item1; -  +     //Add two Barbutton to the left -Self.navigationItem.leftBarButtonItems = @[item1, item2];

(3) in the storyboard to our Navigationbar set the title, or Titleview, is also the use of drag-and-drop configuration of the corresponding properties to complete, in this is not to repeat, the following is given in the method of manual addition, The following code is for our Titleview assignment ImageView, we can also assign him other controls, such as UIButton, etc., the code is as follows:

    //set the value of the titleSelf.navigationItem.title =@"END"; //set up a picture for Titleview//New ImageViewUiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0,0, -, -)]; //set up a pictureUIImage * image = [UIImage imagenamed:@"Topview.png"]; //picture Join ImageViewImageview.image =image; //ImageView joins to NavigationitemSelf.navigationItem.titleView = ImageView;

  4. When switching between views, the following tab bar is present, or reduces our visual space, then how should we hide it? In our storyboard, we just need to select the Hide Bottom Bar on push, and when we switch to the page, we don't see tab Bar, as shown in.

5. System Exit Function: That is, exit to our login interface, the following code can be added to any viewcontroller under Tabview, the code is as follows:

1 // Click the Exit button 2 -(ibaction) Tapexit: (ID) sender {3      [self dismissviewcontrolleranimated: YES completion:^{}]; 4 }

Summary: The above things do not have much advanced technology, with storyboard drag to drag (and give a pure code solution), need our handwritten code to jump between pages of the place we then handwritten jump. After the various Viewcontroller associations above, we can concentrate on implementing the business logic of each of our view after we give each viewcontroller the class of binding entity. When it comes to displaying data in view, TableView uses quite a few. For TableView How to use, in the following blog will be detailed introduction. The above project is configured with storyboard and implements the corresponding code, which works as follows:

  

iOS Development Tabbaritem&navigationbaritem

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.