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];

    }

                     

     

  • 相关阅读:
    .gitignore不生效-git上传忽略解决方案的配置文件
    JAVA
    Java
    python-函数基础01
    Java常见数据结构
    分代垃圾回收机制及垃圾回收算法
    设计模式【9】------>观察者模式
    设计模式【8】------>策略模式
    设计模式【7】------>原型模式
    设计模式【6】------>外观模式
  • 原文地址:https://www.cnblogs.com/yuyu-2012/p/4738928.html
Copyright © 2011-2022 走看看