iOS development UI Chapter-navigationcontroller between the controllers of the jump

Source: Internet
Author: User
Tags uikit

One, the following

1> the first controller Navigationbar hidden

2> has a button, can jump to the next controller, return to the previous controller or the root controller

Second, the idea code

Ideas:

1> Set window with controller Navigationcontroller

2> setting a base class for a controller

The main code is implemented as follows:

Appdelegate.m
  appdelegate.m//  Navigation Simple and practical (pure code)////  Created by Gxiangzi on 15/8/7.//  Copyright (c) 2015 Itcast. All rights reserved.//#import "AppDelegate.h" #import "GXNavController.h" @interface appdelegate () @end @implementation appdelegate-(BOOL) Application: (uiapplication*) Application didfinishlaunchingwithoptions: (NSDictionary*) launchoptions{    Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];    Create a navigation controller    gxnavcontroller* NAVC = [[Gxnavcontroller alloc] init];    Set with controller for navigation controller    Self.window.rootViewController = NAVC;    [Self.window makekeyandvisible];    return YES;} .....

Navigation Controller class: GXNavController.h
#import <UIKit/UIKit.h> @interface Gxnavcontroller:uinavigationcontroller@end

 navigation controller class: GXNAVCONTROLLER.M  
gxnavcontroller.m//Navigation's simple and practical (pure code)////Created by Gxiangzi on 15/8/7.//Copyright (c) 2015 Itcast. All rights reserved.//#import "GXNavController.h" #import "GXFirstController.h" @interface Gxnavcontroller () @ End@implementation gxnavcontroller//overrides the Init method of the parent class, set with controller-(instancetype) init{gxfirstcontroller* first = [[    Gxfirstcontroller alloc] init];    First.view.backgroundColor = [Uicolor Whitecolor]; return [Super Initwithrootviewcontroller:first];}    -(void) viewdidload{[Super Viewdidload]; First hidden navigation bar Self.navigationBar.hidden = YES;} Override the navigation controller's push method, set the return button to back-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated    {//show navigation bar Self.navigationBar.hidden = NO; [Super Pushviewcontroller:viewcontroller animated:animated];}    -(Nsarray *) poptorootviewcontrolleranimated: (BOOL) animated{//First hidden navigation bar Self.navigationBar.hidden = YES; return [Super poptorootviewcontrolleranimated:animated];} @end

Base class: GXBaseViewController.h

#import <UIKit/UIKit.h> @interface gxbaseviewcontroller:uiviewcontroller@property (nonatomic,weak) UIButton * popbtn; @property (nonatomic,weak) UIButton *pushbtn;-(void) pop2previous;-(void) push2next; @end

Base class: GXBASEVIEWCONTROLLER.M

gxbaseviewcontroller.m//Navigation's simple and practical (pure code)////Created by Gxiangzi on 15/8/7.//Copyright (c) 2015 Itcast. All rights reserved.//#import "GXBaseViewController.h" @interface Gxbaseviewcontroller () @end @implementation    gxbaseviewcontroller-(void) viewdidload{[Super Viewdidload];    Create the returned button uibutton* popbtn = [UIButton buttonwithtype:uibuttontypecustom];    [Popbtn settitle:@] returns to the previous controller "Forstate:uicontrolstatenormal";    [Popbtn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal];    Popbtn.backgroundcolor = [Uicolor Graycolor];    Popbtn.frame = CGRectMake (100, 100, 200, 50);    SELF.POPBTN = popbtn;    Create push to Next controller uibutton* pushbtn = [UIButton buttonwithtype:uibuttontypecustom];    [Pushbtn settitle:@ "push to Next Controller" Forstate:uicontrolstatenormal];    [Pushbtn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal];    Pushbtn.backgroundcolor = [Uicolor Graycolor];    Pushbtn.frame = CGRectMake (100, 300, 200, 50); SELF.PUSHBTN = PUSHBTN    Register Listener Event [self.popbtn addtarget:self Action: @selector (pop2previous) forcontrolevents:uicontroleventtouchupinside]; [Self.pushbtn addtarget:self Action: @selector (Push2next) forcontrolevents:uicontroleventtouchupinside];}
#pragma mark-Subclass rewrite #pragma mark-previous-(void) pop2previous{[Self.navigationcontroller Popviewcontrolleranimated:yes];} #pragma mark-Next-(void) push2next{[Self.navigationcontroller pushviewcontroller:nil animated:yes];} @end

iOS development UI Chapter-navigationcontroller between the controllers of the jump

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.