日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

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

iOS UITableView一些基礎知識

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

打開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下!
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 日韩国产精 | 一区二区三区高清 | 精品久久网站 | 91精品一区二区三区久久久久久 | 中文字幕亚洲一区二区三区 | 综合久久一区二区三区 | 国产精品免费一区 | 福利视频网址 | 精品美女一区二区 | 欧美夜夜操 | 国av级一级理论片 | 青青草国产成人av片免费 | 麻豆成人久久精品二区三区小说 | 日韩视频一区二区在线 | 国产精品区在线观看 | 国产精品18久久久 | 亚洲www啪成人一区二区麻豆 | 爱情岛论坛首页永久网址 | 欧美精品大片 | 日日操天天操夜夜操 | www.青青| 99精品免费观看 | 亚洲www| 日韩中文字幕网址 | 日韩免费视频一区二区 | 国产麻豆乱码精品一区二区三区 | 日韩aⅴ视频 | 91精品一区二区三区久久久久 | 国产午夜精品久久久久久免费视 | 国产在线国偷精品免费看 | 三级在线看 | 国产成人在线播放 | a视频在线| 正在播放国产一区 | 国产精品久久国产三级国电话系列 | 日韩一区二区在线视频 | 7799精品视频 | 欧洲av一区二区 | 色综合久久久 | 亚洲视屏 | 免费一区二区 |