一. 設置tableViewCell的系統樣式都知道tableView的創建有兩種方式第一種是注冊 第二種是非注冊形式的 首先收一下tableView的樣式:
UITableViewStylePlain和UITableViewStyleGrouped兩種 至于兩種tableView的樣式大家可以自己來驗證
下面來談談tableViewCell的系統樣式
- 注冊的cell樣式: cell只有textLabel一個屬性 而且textLabel在最左側
-
非注冊的形式
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reuse"];
}
(1). UITableViewCellStyleDefault
有屬性 cell.imageView cell.textLabel 兩個屬性
imageView在最左側 label在imageView旁邊 如下圖所示
3A486217-6BE5-4F88-8392-4333B62766C7.png
(2). UITableViewCellStyleSubtitle
有屬性 cell.imageView cell.textLabel detailTextLabel 三個屬性
D43043F3-75FF-4914-A667-13A14BE672B4.png
(3) UITableViewCellStyleValue1
有屬性 cell.imageView cell.textLabel detailTextLabel 三個屬性
0B580F7C-0D8B-4BDA-B5FA-CB08679F4432.png
(4) UITableViewCellStyleValue2
有屬性 cell.textLabel detailTextLabel 兩個屬性
2D425E3C-8C4C-4517-AE48-C2D0DB297399.png
總結一下下 如果使用注冊的方式創建tableView只有一個cell.textLabel一個屬性 如果還需要其他的控件就需要自己取自定義cell
二.關于tableView設置的一些小細節
我們在創建tableView時候 常常會遇到各位各樣影響UI效果的現象 比如tableViewCell之間的線 cell被選中時的狀態...下面 我們就來總結一下這些小細節
- sectionHeaderHeight(sectionHeaderFooter) ------ 當tableView為UITableViewStyleGrouped時 設置分區頭(尾)高度的屬性
// 2. 設置分割線的樣式
// self.tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
// 3. cell選中時的樣式
// cell.selectionStyle
// 4. 在tableView非編輯狀態下是否可以選中 默認為yes
// self.tabelView.allowsSelection
// 5. 是否可以選中多行 默認為NO
// self.tabelView.allowsMultipleSelection
// 6. 選中多行時是否可以編輯 默認為NO
// self.tabelView.allowsMultipleSelectionDuringEditing
// 7. tableView頭視圖
// self.tabelView.tableHeaderView
// 8. 進入編輯模式
// [self.tabelView setEditing:YES animated:YES];
// 9. 獲取某個組的頭標簽的位置和大小
// [self.tabelView rectForHeaderInSection:<#(NSInteger)#>]
// 10. 獲取某一行的位置和大小
// [self.tabelView rectForRowAtIndexPath:<#(nonnull NSIndexPath *)#>]
// 11. 通過cell路徑找到cell
// cellForRowAtIndexPath
// 12. 當添加或者刪除cell時更新 (endUpdates)
// beginUpdates
// 13. 插入一個或者多個組使用動畫 插入一個或者多個行 使用動畫 有插入同樣有delete
// insertSections: withAnimation:
// self.tabelView insertRowsAtIndexPaths:<#(nonnull NSArray<NSIndexPath *> *)#> withRowAnimation:<#(UITableViewRowAnimation)#>
// 14. 更新cell或者section
// self.tabelView reloadRowsAtIndexPaths:<#(nonnull NSArray<NSIndexPath *> *)#> withRowAnimation:<#(UITableViewRowAnimation)#>
// self.tabelView reloadSections:<#(nonnull NSIndexSet *)#> withRowAnimation:<#(UITableViewRowAnimation)#>
// 15. 移動section或者cell
// self.tabelView moveRowAtIndexPath:<#(nonnull NSIndexPath *)#> toIndexPath:<#(nonnull NSIndexPath *)#>
// self.tabelView moveSection:<#(NSInteger)#> toSection:<#(NSInteger)#>
// 16. 返回選擇的一個cell或多個路徑
// indexPathsForSelectRow
// indexPathsForSelectRows
// 17. 設置選中某個區域的單元格
// selectRowAtIndex: animation: scrollPosition
// 18. 取消選中的單元格
// deselectRowAtIndexPath: animation:
// dequeueReusableCellWithIdentifier:---------獲取重用隊列里的單元格
// 二. UITableViewDataSource代理方法:
// 方法:
// 1. numberOfSectionsInTableView:------------設置表格的組數
// 2. tableView:numberOfRowInSection:----------設置每個組有多少行
// 3. tableView:cellForRowAtIndexPath:---------設置單元格顯示的內容
// 4. tableView:titleForHeaderInSection:---------設置組表的頭標簽視圖
// 5. tableView:titleForFooterInSection:-----------設置組表的尾標簽視圖
// 6. tableView:canEditRowAtIndexPath:---------設置單元格是否可以編輯
// 7. tableView:canMoveRowAtIndexPath:--------設置單元格是否可以移動
// 8. tableView:sectionIndexTitleForTableView:atIndex:-------設置指定組的表的頭標簽文本
// 9. tableView:commitEditingStyle:forRowAtIndexPath:----------編輯單元格(添加,刪除)
// 10. tableView:moveRowAtIndexPath:toIndexPath-------單元格移動
// 三. UITableViewDelegate代理方法:
//
// 1. tableView: willDisplayCell: forRowAtIndexPath:-----------設置當前的單元格
//
// 2. tableView: heightForRowAtIndexPath:-----------設置每行的高度
// 3. tableView:tableView heightForHeaderInSection:-----------設置組表的頭標簽高度
// 4. tableView:tableView heightForFooterInSection:-------------設置組表的尾標簽高度
// 5. tableView: viewForHeaderInSection:----------自定義組表的頭標簽視圖
// 6. tableView: viewForFooterInSection: ----------自定義組表的尾標簽視圖
//
// 7. tableView: accessoryButtonTappedForRowWithIndexPath:-----------設置某個單元格上的右指向按鈕的響應方法
//
// 8. tableView: willSelectRowAtIndexPath:-----------獲取將要選擇的單元格的路徑
// 9. tableView: didSelectRowAtIndexPath:-----------獲取選中的單元格的響應事件
// 10.tableView: tableView willDeselectRowAtIndexPath:------------獲取將要未選中的單元格的路徑
// 11. tableView: didDeselectRowAtIndexPath:-----------獲取未選中的單元格響應事件
不吹牛逼 以上的這些關于tableView的方法如果都掌握了 那么 你就是下一個tableView小能手 是不是酷酷的 關于tableView的分享就到這里 ...
未完待續......