【UIKit】UITableView.03

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   os   io   檔案   

UITableView.03:

 

【1】拖入一個UITableView

【2】將TableView的dataSource與控制器串連

【3】首先得遵循UITableView的資料來源協議<UITableViewDataSource>

【4】加入表徵圖檔案

【5】代碼

 

1.設定一共多少組,系統預設是1組,所以不寫的話就預設1組

#pragma mark 返回多少組-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    // 在這裡預設是1,寫與不寫一樣    return 1;}

2.返回多少行,這裡返回9行

#pragma mark 返回一組多少行-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return 9;}

3.返回每一行的具體資料

  下表為箭頭樣式

UITableViewCellAccessoryCheckmark
  
UITableViewCellAccessoryDetailButton
UITableViewCellAccessoryDetailDisclosureButton
  
UITableViewCellAccessoryDisclosureIndicator
  
UITableViewCellAccessoryNone
表示沒有
#pragma mark 返回具體資料-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle                                            reuseIdentifier:nil];  /************************設定左邊表徵圖*******************/    // 1.取出第i行所使用的圖片名稱    NSString *imageName=[NSString stringWithFormat:@"00%d.png",indexPath.row+1];   // 2.cell.imageView.image=上面取得的image的名字    cell.imageView.image=[UIImage imageNamed:imageName];    /***********************設定主標題*********************/    [email protected]"12312432";
// 設定子標題,需要在上面的UITableViewCellStyleDefault改為UITableViewCellStyleSubtitle [email protected]"詳細描述"; //子標題內容為詳細描述 // 設定cell箭頭樣式 cell.accessoryType=UITableViewCellAccessoryCheckmark; return cell; }

 

4.設定每一行的行高

  1)加入代理

2) 添加代理協議<UITableViewDelegate>

3) 調整高度

#pragma mark- 調整每一行的高度,代理方法-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    // 設定所有高度為70;        return 60;        // 也可以根據傳入的不同內容進行不同的高度設定    // 行數越多,高度越高    //return 40+indexPath.row*5;   }
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.