zoukankan      html  css  js  c++  java
  • 用UIButton实现页面跳转(AppDelegate +NavigationViewController)

    1.AppDelegate.h

    定义一个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]];//实例化window

        MainViewController *mainViewController = [[MainViewController alloc]init];//实例化mainView控制器

         //把mainView控制器放到navigationController的方法中,使之成为根控制器

        _navigationCotroller = [[UINavigationController alloc] initWithRootViewController:mainViewController];

        [_window addSubview:_navigationCotroller.view];//window中加载导航控制器的view

        [self.window makeKeyAndVisible];//视图可见

     

        return YES;

    }

    3.mainViewController.m

    设置按钮的页面,按钮触发的方法中,调用AppDelegate中的导航控制器的pushViewController方法,实现页面跳转(自动生成有返回健的页面)。

    按钮触发的方法:

    [_logonBtn addTarget:self action:@selector(loginClick:) forControlEvents:UIControlEventTouchUpInside];

    页面跳转:

    -(void)loginClick:(id)sender{

        LogonViewController *logonView = [[LogonViewController alloc]init];

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

        [myDelete.navigationCotroller pushViewController:logonView animated:YES];

    }

                     

     

  • 相关阅读:
    类单元实验?(不成功)
    类的组合
    实验2
    C++ work 1 switch and while
    Python 学习笔记 0308 周二:tuple,list,dict的区别
    Python 学习笔记 0307 周一:lambda函数和整数判断
    mac搭建python环境
    我也想犯这些错误【2】初始化之前变量的默认值
    毕业三年。
    我也想犯这些错误【1】c#的值类型和引用类型
  • 原文地址:https://www.cnblogs.com/yuyu-2012/p/4738928.html
Copyright © 2011-2022 走看看