標籤: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; }