• UI基础 导航控制器


    app .m

    #import "AppDelegate.h"
    #import "RootViewController.h"
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        
        
        RootViewController * root=[[RootViewController alloc]init];
    //    self.window.rootViewController=root;
        //创建导航控制器
        UINavigationController *nav =[[UINavigationController alloc]initWithRootViewController:root];
        
        //把导航控制器作为window的视图
        self.window.rootViewController =nav;
        //导航栏的颜色
        nav.navigationBar.barTintColor=[UIColor greenColor];
        
        //半透明
        nav.navigationBar.translucent=NO;
        
        
        
            
        
        
        return YES;
    }

    root.m

    #import "RootViewController.h"
    #import "SecondViewController.h"
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    //    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    //
    //    view.backgroundColor=[UIColor redColor];
    //    [self.view addSubview:view];
    //
    
        //把控制导航栏内容代码写到对应的页面上来
        self.navigationItem.title=@"首页";
        
    //    self.navigationItem.titleView=
        //左右侧的按钮 文字
    //    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"右侧" style:UIBarButtonItemStylePlain target:self action:@selector(touchRight)];
    // 图片
        self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Processsettings"] style:UIBarButtonItemStylePlain target:self action:@selector(touchRight)];
        
        
    
        
    }
    
    -(void)touchRight
    {
        NSLog(@"右侧");
        
        SecondViewController *second =[[SecondViewController alloc]init];
        //跳转
        [self.navigationController pushViewController:second animated:YES];
        
        
    }
    @end

    second.m

    #import "SecondViewController.h"
    
    @interface SecondViewController ()
    
    @end
    
    @implementation SecondViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor =[UIColor greenColor];
        
    //    第二个页面左上角返回按钮
        self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
    
    }
    
    -(void)goBack
    {
    //    从哪里回到上一个
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    }
    
    @end
  • 相关阅读:
    Jmeter环境搭建
    python基础(四)
    python基础(三)
    python基础(二)
    python基础(一)
    jmeter压测、操作数据库、分布式linux下运行、webservice接口测试、charles抓包
    接口测试及其工具简单使用
    Linux安装jdk
    使用loadrunner监控apcahe
    LoadRunner监控Linux
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13430824.html
Copyright © 2020-2023  润新知