多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > iOS UITableView一些基礎知識

iOS UITableView一些基礎知識

來源:程序員人生   發布時間:2015-03-27 08:01:41 閱讀次數:2566次

打開UIViewController.h


//

//  RootViewController.h

//  Lesson09TableView

//

//  Created by Dubai on 14⑼⑵6.

//  Copyright (c) 2014 Dubai All rights reserved.

//


#import <UIKit/UIKit.h>

//遵守1下代理

@interface RootViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>


@end


打開 UIViewController.m為:


//

//  RootViewController.m

//  Lesson09TableView

//

//  Created by Dubai on 14⑼⑵6.

//  Copyright (c) 2014 Dubai All rights reserved.

//


#import "RootViewController.h"


@interface RootViewController ()


@end


@implementation RootViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:(UITableViewStyleGrouped)];

    

    [self.view addSubview:tableView];

    [tableView release];

    

    //屬性

    

    tableView.rowHeight = 90;//行高

    tableView.separatorColor = [UIColor redColor];//行隔性色彩

    //tableView.separatorStyle = UITableViewScrollPositionNone;//分割線 消失

    //tableView.separatorStyle = UITableViewScrollPositionBottom;

    //tableView.separatorStyle = UITableViewRowAnimationRight;

    

    

    tableView.dataSource = self;//設置數據源的代理(必須實現)

    tableView.delegate = self;//負責控制的代理對象

    

    

}



//設置分區,可選實現,由于tableview默許有1個分區(數據源代理)


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 4;


}


//設置每一個分區的行數,必須實現(數據源)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return 5;

    

}

//設置每行要顯示的內容,每行所在位置會放值1個tabelViewcell,每行要顯示的數據,設置在cell上必須實現


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath


{

    

    //當某行移出屏幕時,tableView會將這行顯示的cell,移動到重用集合中貯存,這行就咩有cell顯示任何數據.

    //因此,只要某行要進入屏幕顯示,必須履行這個代理方法.設置這行要顯示的cell;

    NSLog(@"row= %ld",indexPath.row);

    

    

  //indexPath包括兩個屬性 section row 即分區和行數

    //section row 的索引都從0開始.每一個分區中的row的索引都是從0開始

    

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];

    //cell的樣式 是用來影響3個視圖的位置

    

    //cell.imageView.image = [UIImage imageNamed:@"ha.png"];

    

    //cell.detailTextLabel  直接用 不用創建(不能改變大小)

    cell.textLabel.text = [NSString stringWithFormat:@" section:%ld row:%ld",indexPath.section,indexPath.row];//在第幾個分區 第幾行

    cell.detailTextLabel.text = @". . . .";//當是default時不顯示(可以修改cell樣式 來顯示)

    

    //cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//輔助視圖

    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    

    //只讓第1行顯示checkmark

    if (indexPath.row == 0) {

        //如果是第1行就顯示為checkmark

        cell.accessoryType = UITableViewCellAccessoryCheckmark;

    }else{

    

        cell.accessoryType = UITableViewCellAccessoryNone;

    

    

    }

    

    

    

    return cell;

    

    

    

//    //重用

//    

//    //先從重用隊列中獲得可以被重用的cell對象,

//    

//    static NSString *indentifier = @"cell";//標示

//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];

//    //如果重用隊列中沒有可使用的cell,必須自己創建.

//    if (cell == nil) {

//        cell = [[[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:indentifier] autorelease];

//        NSLog(@"創建的新的cell對象");//只許創建對象

//        

////        cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];

//        

//    }

//    //重用在這里

//    //設置當前要使用的cell,可能放置在任何1行

//    cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];

//    //cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.section];

//    cell.detailTextLabel.text = [NSString stringWithFormat:@"nihao"];//顯示不顯示跟上面的cell創建時的subtitle有關

//    return cell;

}


//給每一個分區設置頭部標題

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{



    return [NSString stringWithFormat:@"%ld",section + 1];




}


//給所有的副標題右邊的.


- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

{


    return @[@"1",@"2",@"3"];



}


////設置行高

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

//{

//    if (indexPath.section == 0) {

//        return 20;

//    }if (indexPath.section == 1) {

//        return 60;

//    }if (indexPath.section == 2) {

//        return 40;

//    }if (indexPath.section == 3) {

//        return 100;

//    }return 2;

//

//

//}

//

//檢測cell被選中的第幾個分區第幾行


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{


    NSLog(@"分區   %ld,行數:%ld",indexPath.section+1,indexPath.row );




}

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end


如圖:


1些UItableView的復雜用途與難點以后我會給大家整理1下!
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 精品福利一区 | 国产午夜免费一区二区三区 | 中文国产成人精品久久一 | 都市激情校园春色亚洲 | 日本www高清免费视频观看 | 免费一级毛片在级播放 | 精品伊人 | 欧美极品video粗暴 | 日韩免费一区二区三区在线 | 在线视频观看一区 | 国产免费一区二区三区在线观看 | 亚洲日韩第一页 | 欧美性一区二区三区五区 | www.噜噜噜| 羞羞视频免费网站日本 | 曰本人一级毛片免费完整视频 | 最近的中文字幕视频完整 | 亚洲黄色在线看 | 男女性刺激爽爽免费视频 | 欧美交| 成人一级网站 | 伊人久久大香 | 91人人爱| 天天夜夜狠狠 | 日韩精品欧美亚洲高清有无 | chinesehd国产刺激对白 | 99久久精品男女性高爱 | 成人夜夜嗨| 亚洲 欧美 都市 自拍 在线 | 精品乱人伦一区二区 | 午夜久久视频 | 你操综合| xxxx网 | 小说区 | 亚洲一成人毛片 | 欧美激情综合亚洲五月蜜桃 | 欧美一区二区三区不卡视频 | 伊人久久中文大香线蕉综合 | 亚洲欧洲国产视频 | 日韩爱爱 | h免费视频 |