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;

    }

  • 相关阅读:
    Codeforces 371D Vessels
    HDU1272小希的迷宫–并查集
    golang:exported function Script should have comment or be unexported
    动态规划--0,1背包问题(再也不怕类似背包问题了)
    golang数据结构之稀疏数组
    向github中已创建好的repository提交文件
    java(二)变量
    使用Git上传文件到github
    java(一)基础知识
    pytorch--基础类型之间的转换
  • 原文地址:https://www.cnblogs.com/yuyu-2012/p/4790142.html
Copyright © 2011-2022 走看看