• iOS:使用导航栏


    要求使用ARC

    //
    //  main.m
    //  Hello
    //
    //  Created by lishujun on 14-8-28.
    //  Copyright (c) 2014年 lishujun. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    
    // --------------视图控制器对象--------------
    @interface HelloWorldViewController : UIViewController
    @end
    
    @implementation HelloWorldViewController
    
    -(void) loadView
    {
        NSLog(@"load View");
        //创建视图对象
        UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        contentView.backgroundColor = [UIColor lightGrayColor];
        self.view = contentView;
        
        //设置导航栏按钮,被加载的到UINavigationController才可以使用这个属性?
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(pushView:)];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Prev" style:UIBarButtonItemStylePlain target:self action:@selector(popView:)];
    }
    
    -(void) pushView:(id)sender
    {
        NSLog(@"push view");
        [self.navigationController pushViewController:[[HelloWorldViewController alloc]init] animated:YES];
    }
    
    -(void) popView:(id)sender
    {
        NSLog(@"pop view");
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    @end
    
    
    // ----------------委托对象--------------------
    @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate>
    {
        IBOutlet UIWindow *window;
    }
    
    @property (nonatomic, retain) UIWindow *window;
    @property (nonatomic, retain) UINavigationController *nav;
    
    @end
    
    @implementation HelloWorldAppDelegate
    
    @synthesize window;
    @synthesize nav;
    
    -(void) applicationDidFinishLaunching:(UIApplication *)application
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
        HelloWorldViewController *viewController = [[HelloWorldViewController alloc]init];
        
        self.nav = [[UINavigationController alloc]initWithRootViewController: viewController];
        self.window.rootViewController = self.nav;
        [self.window makeKeyAndVisible];
    }
    @end
    
    // ---------------程序入口---------------------
    int main(int argc, char * argv[])
    {
        @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
        }
    }
  • 相关阅读:
    关于css兼容性问题及一些常见问题汇总
    CSS3使用transition属性实现过渡效果
    CSS3 画基本图形,圆形、椭圆形、三角形等
    总结30个CSS3选择器
    javascript中call()、apply()的区别
    JavaScript面试技巧之数组的一些不low操作
    详解bootstrap-fileinput文件上传控件的亲身实践
    js控制随机数生成概率代码实例
    jQuery 第十章 工具方法-高级方法 $.ajax() $.Callbacks() .....
    jQuery 第九章 工具方法之插件扩展 $.extend() 和 $.fn.extend()
  • 原文地址:https://www.cnblogs.com/code-style/p/3951791.html
Copyright © 2020-2023  润新知