Page Jump (Navigaitoncontroller) + with auto-return in IOS

Source: Internet
Author: User

Page 1 skip to page 2

The code is as follows:

1.appdelegate.h

#import <UIKit/UIKit.h>

@interface appdelegate:uiresponder <uiapplicationdelegate>

@property (Strong, nonatomic) uiwindow *window;

@property (Strong, nonatomic)uinavigationcontroller *navigationcontroller;

@end

2. APPDELEGATE.M

#import "AppDelegate.h"

#import "FirstViewController.h"

@interface appdelegate ()

@end

@implementation appdelegate

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

UIWindow *window = [[uiwindow alloc]initwithframe: [[UIScreen Mainscreen] Bounds]];

Firstviewcontroller *viewcontroller = [[Firstviewcontroller alloc]initwithnibname:@ " Firstviewcontroller " bundle:nil";

_navigationcontroller = [[uinavigationcontroller alloc]initwithrootviewcontroller: Viewcontroller];

[Self. Window addsubview: _navigationcontroller. View];

self. Window. Rootviewcontroller = _navigationcontroller;

Self.window.rootViewController = Viewcontroller;

[self. Window makekeyandvisible];

return YES; return YES;

}

3. FirstViewController.h

#import <UIKit/UIKit.h>

@interface Firstviewcontroller: uiviewcontroller{

}

-(ibaction) Presstosecond: (ID) sender;

@end

4.firstviewcontroller.m

#import "FirstViewController.h"

#import "SecondViewController.h"

#import "AppDelegate.h"

@interface firstviewcontroller ()

@end

@implementation Firstviewcontroller

-(void) Viewdidload {

[Super Viewdidload];

[Self.next addtarget:self Action: @selector (Presstosecond:) forcontrolevents:uicontroleventtouchupinside];

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}

-(ibaction) Presstosecond: (ID) sender {

Secondviewcontroller *secondview = [[Secondviewcontroller alloc]initwithnibname:@ " Secondviewcontroller " bundle:nil";

page Jump:

Method 1: (Can't pass the value, do not know why??? )

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

[MyDelegate. Navigationcontroller pushviewcontroller:secondview animated:YES];

}

@end

This can have the above effect, but if Secondviewcontroller set this controller's Navigationcontroller

Navigationbar will not automatically display the return button, you need to set up in the Secondviewcontroller.

-(void) Viewdidappear: (BOOL) animated{

[Super viewdidappear:animated];

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

MyDelegate.navigationController.navigationBarHidden = YES;

self. Navigationcontroller. Navigationbarhidden = YES;

}

Page Jump (Navigaitoncontroller) + with auto-return in IOS

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.