Implement page jump with UIButton (appdelegate +navigationviewcontroller)

Source: Internet
Author: User

1.appdelegate.h

Define a Uinavigationcontroller

#import <UIKit/UIKit.h>

#import "MainViewController.h"

@interface appdelegate:uiresponder <uiapplicationdelegate>

@property (Strong, nonatomic) uiwindow *window;

@property (Strong, nonatomic) uinavigationcontroller *navigationcotroller;

@end

2.appdelegate.m

#import "AppDelegate.h"

@interface appdelegate ()

@end

@implementation appdelegate

-(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions {

self. Window = [[uiwindow alloc]initwithframe: [[uiscreen mainscreen]bounds]];/ /Instantiate window

Mainviewcontroller *mainviewcontroller = [[Mainviewcontroller alloc]init];// Instantiating a Mainview controller

//Put the Mainview controller in the Navigationcontroller method to make it a root controller

_navigationcotroller = [[uinavigationcontroller alloc] initwithrootviewcontroller: Mainviewcontroller];

[_window addsubview: _navigationcotroller. View ofthe navigation controller loaded in the view];//window

[self. Window makekeyandvisible];//view visible

return YES;

}

3.mainviewcontroller.m

Set the button's page, the button trigger method, call Appdelegate in the navigation controller's Pushviewcontroller method, implement the page jump (automatically generate a return to the health of the page).

Method of button triggering:

[_logonbtn addTarget:self Action:@selector(loginclick:) forcontrolevents: UIControlEventTouchUpInside];

Page Jump:

-(void) Loginclick: (ID) sender{

Logonviewcontroller *logonview = [[Logonviewcontroller alloc]init];

appdelegate *mydelete = [[uiapplication sharedapplication]delegate];

[Mydelete. Navigationcotroller pushviewcontroller:logonview animated:YES];

}

Implement page jump with UIButton (appdelegate +navigationviewcontroller)

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.