zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    设计tag的sql语句,支持每个tag的个数,Access数据库非msSql
    ulObj ul = new ulObj();
    Access 日期比较用 #扩住日期 代码如下
    dw中IMG标记的正则替换
    许涛的 repeater itemCommand 事件代码(经典代码,不难)
    n1视觉图片列表样式[jquery代码][A标记里面一个IMG一个EM]
    flashbox小组件开发~~开源~~
    动态读取一张图片到mc里,读取txt中的内容 flash as 全站flash专题
    简单的jQueryTab 自写的小代码
    flashCs3 按钮事件没了?原来As3已经改为监听模式了!
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13430824.html
Copyright © 2011-2022 走看看