zoukankan      html  css  js  c++  java
  • 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;

    }

  • 相关阅读:
    Mybatis插件之Mybatis-Plus的实体类注解篇
    Mybatis插件之Mybatis-Plus(SpringBoot)
    Mybatis插件之Mybatis-Plus(传统模式)
    Java中简单测试FastDFS的文件上传
    Linux下部署FastDFS
    SpringBoot中使用 RabbitMQ -测试
    RabbitMQ的安装(Windows环境下)
    SpringBoot中使用aop-测试
    正则表达式之图文混排
    正则表达式的使用总结
  • 原文地址:https://www.cnblogs.com/yuyu-2012/p/4790142.html
Copyright © 2011-2022 走看看