iOS之UITableView

來源:互聯網
上載者:User

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.