導航視圖控制器學習筆記

//  AppDelegate.m

//  UI07_導航視圖控制器

//

//  Created by dllo on 15/8/6.

//  Copyright (c) 2015 cml. All rights reserved.

//


#import "AppDelegate.h"

#import "MainViewController.h"

@interface AppDelegate ()


@end


@implementation AppDelegate

-(void)dealloc{

    [_window release];

    [super dealloc];

}


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

    [_window release];

    

    // 先創建一個ViewController

    MainViewController *mainVC =[[MainViewController alloc] init];

    // 創建導航視圖控制器

    UINavigationController *naVC=[[UINavigationController alloc] initWithRootViewController:mainVC];

    //

    self.window.rootViewController =naVC;

    // 釋放

    [mainVC release];

    [naVC release];






//  MainViewController.m

//  UI07_導航視圖控制器

//

//  Created by dllo on 15/8/6.

//  Copyright (c) 2015 cml. All rights reserved.

//


#import "MainViewController.h"

#import "SecondViewController.h"

@interface MainViewController ()



@property(nonatomic,retain)UITextField *textfield;


@end


@implementation MainViewController

-(void)dealloc{

    [_textfield release];

    [super dealloc];

}



- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor =[UIColor orangeColor];

    

    // 導航控制器高度是44,上面的狀態欄高度是20,加在一起默認是64

    

    UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];

    button.frame =CGRectMake(240, 540, 100, 40);

    button.layer.borderWidth=1;

    button.layer.cornerRadius=10;

    [self.view addSubview:button];

    [button setTitle:@"下一頁" forState:UIControlStateNormal];

    

    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

    

    

    // 對導航視圖進行設置

    // 加上一個標題

//    self.title =@"貓眼電影";

    

    // 外觀進行設置

    // 背景顏色的設置

    // 不是所有的背景顏色都是backgroundColor

    // 默認是半透明的

//    self.navigationController.navigationBar.barTintColor=[UIColor greenColor];

    self.navigationController.navigationBar.translucent=NO;

    // 創建一個UIView

    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

    [view setBackgroundColor:[UIColor blackColor]];

    [self.view addSubview:view];

    [view release];

    

    // 爲了防止座標系被改變,我們把bar從半透明設置成不透明,這樣座標系的圓點會自動向下推64

//    self.navigationController.navigationBar.translucent=NO;

    

    

    // 內容方面的設置

    // 標題設置

//    self.navigationItem.title=@"電影";

    

    

    // 指定一些視圖, 稱爲titleView

    UISegmentedControl *seg=[[UISegmentedControl alloc] initWithItems:@[@"信息",@"通話" ]];

    self.navigationItem.titleView =seg;

    

    // 創建左右兩邊的按鈕

//    self.navigationItem.leftBarButtonItem =[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(leftButtonClick:)] autorelease];

    

//    self.navigationItem.leftBarButtonItem =[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(leftButtonClick:)] autorelease];

    

    self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"雙子"] style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonClick:)];

    

    //

//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"雙子"] style:UIBarButtonItemStylePlain target:self action:@selector(rigthButtonClick:)];

//    self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"雙子"] style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonClick)];

    

    

    // 創建一個小button

    UIButton *rightButton=[UIButton buttonWithType:UIButtonTypeCustom];

    rightButton.frame=CGRectMake(0, 0, 40, 40);

    [rightButton setImage:[UIImage imageNamed:@"雙子"] forState:UIControlStateNormal];

    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:rightButton];

    

    

    self.textfield =[[UITextField alloc] initWithFrame:CGRectMake(100, 200, 100, 40)];

    self.textfield.layer.borderWidth =1;

    self.textfield.layer.cornerRadius =10;

    [self.view addSubview:self.textfield];

    [_textfield release];

    

}


-(void)leftButtonClick:(UIBarButtonItem *)barBUtton

{

    

}


-(void)rigthButtonClick:(UIBarButtonItem *)Button{

    

}



-(void)click:(UIButton *)button{

    // 用模態跳轉下一頁

//    SecondViewController *secondView=[[SecondViewController alloc] init];

//    [secondView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

//    [self presentViewController:secondView animated:YES completion:^{

//    }];

//    [secondView release];

    

    // 通過導航控制器進行跳轉

    // 先創建下一頁的對象

    SecondViewController *secondView =[[SecondViewController alloc] init];

    //

    // 屬性傳值的第二步

    secondView.number =100;

    

    secondView.str =self.textfield.text;

    

    secondView.arr =@[@"1",@"2",@"3"];

    

    

    [self.navigationController pushViewController:secondView animated:YES];

    [secondView release];

    

}


//

//  SecondViewController.h

//  UI07_導航視圖控制器

//

//  Created by dllo on 15/8/6.

//  Copyright (c) 2015 cml. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface SecondViewController : UIViewController


// 屬性傳值第一步 ,在第二個頁面寫一條屬性

@property(nonatomic ,assign)NSInteger number;

// 針對字符串寫一條屬性

@property(nonatomic ,copy)NSString *str;


@property(nonatomic ,retain)NSArray *arr;

@end


//  SecondViewController.m

//  UI07_導航視圖控制器

//

//  Created by dllo on 15/8/6.

//  Copyright (c) 2015 cml. All rights reserved.

//


#import "SecondViewController.h"

#import "ThirdViewController.h"

@interface SecondViewController ()


@property(nonatomic ,retain)UILabel *label;


@end


@implementation SecondViewController


-(void)dealloc{

    [_label release];

    [_str release];

    [_arr release];

    [super dealloc];

}


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor =[UIColor yellowColor];

    UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];

    button.frame =CGRectMake(240, 540, 100, 40);

    button.layer.borderWidth=1;

    button.layer.cornerRadius=10;

    [self.view addSubview:button];

    [button setTitle:@"下一頁" forState:UIControlStateNormal];

    

    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

    

    UIButton *button1 =[UIButton buttonWithType:UIButtonTypeSystem];

    button1.frame =CGRectMake(120, 540, 100, 40);

    button1.layer.borderWidth=1;

    button1.layer.cornerRadius=10;

    [self.view addSubview:button1];

    [button1 setTitle:@"上一頁" forState:UIControlStateNormal];

    

    [button1 addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside];

    NSLog(@"%ld",self.number);

    

    

    self.label =[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 40)];

    self.label.backgroundColor =[UIColor cyanColor];

    [self.view addSubview:self.label];

    [self.label release];

    

    // 把屬性裏的內容對label進行賦值

    self.label.text =self.str;

    

    NSLog(@"%@",self.arr[1]);

    

    

    

}

-(void)click:(UIButton *)button{

    ThirdViewController *thirdView=[[ThirdViewController alloc] init];

   

    [self.navigationController pushViewController:thirdView animated:YES];

    [thirdView release];

    

}


-(void)click1:(UIButton *)button{

    [self.navigationController popViewControllerAnimated:YES];

}











發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章