IOS 中的页面跳转(navigaitonController)+带自动返回

页面1                                                                      跳至                                  页面2

        

 

代码如下:

 

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 that can be recreated.

}

 

 

 

- (IBAction)pressToSecond:(id)sender {

    SecondViewController *secondView = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];

    

//        页面跳转:

//        方法1:(传不了值,不知道为什么???)

        AppDelegate *myDelegate = [[UIApplication sharedApplication]delegate];

        [myDelegate.navigationController pushViewController:secondView animated:YES];

    

    

}

@end

这样就可以有上面的效果了,但是如果secondViewController里设置此controller的navigationController的

navigationBar就不会自动显示返回按钮了,需要在secondViewController里设置一下。

-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

    AppDelegate *myDelegate = [[UIApplication sharedApplication]delegate];

    //    myDelegate.navigationController.navigationBarHidden = YES;

    self.navigationController.navigationBarHidden = YES;

}

 

转载于:https://www.cnblogs.com/yuyu-2012/p/4790142.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值