iOS之UITableView
UITableViewDelegate協議方法
返回每一行儲存格的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
返回分區區頭的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
返回分區區角的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
返回分區區頭的自訂View(可以使用重用機制)
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
返回分區區腳的自訂View(可以使用重用機制)
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
儲存格右側附件按鈕點擊時執行的方法
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
將要選中儲存格的時候執行的方法
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
不選中儲存格執行的方法
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
選中儲存格時候執行的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
取消選中儲存格時候執行的方法
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
設定每一個儲存格的編輯風格
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
UITableViewCellEditingStyleNone,
UITableViewCellEditingStyleDelete,
UITableViewCellEditingStyleInsert
設定按鈕的標題
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
設定儲存格是否需要縮排
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
儲存格即將編輯時執行的方法
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
儲存格完成編輯時候執行的方法
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
儲存格在移動過程中執行的方法
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
是否顯示菜單的複製粘貼
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
UITableViewDataSource協議方法
必須實現:
每個分區有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
每個儲存格的內容(儲存格有重用機制,並且可以自訂)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
非必須實現:
有多少分區(預設為1)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
分區區頭標題
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
分區區腳標題
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
設定儲存格是否可以編輯
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
設定儲存格是否可以移動
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
設定表格右側的索引數組
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
設定表格的索引和分區的對應關係
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
提交儲存格編輯狀態的時候執行的方法(即添加.刪除按鈕)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
儲存格移動的時候執行的方法(從初始位置到目標位置)
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath