第三章:IOS Table表視圖委託協議和資料協議,iostable
表視圖有兩個重要的協議
UITableViewDataSource :資料來源協議
| 方法 |
傳回型別 |
說明 |
必須實現 |
tableView:cellForRowAtIndexPath: |
UITableViewCell* |
為表視圖儲存格提供資料,該方法是必 須實現的方法 |
是 |
tableView:numberOfRowsInSection: |
NSInteger |
返回某個節中的行數 |
是 |
tableView:titleForHeaderInSection: |
NSString |
返回節頭的標題 |
否 |
tableView:titleForFooterInSection: |
NSString |
返回節腳的標題 |
否 |
numberOfSectionsInTableView: |
NSInteger |
返回節的個數 |
否 |
sectionIndexTitlesForTableView: |
NSArray* |
提供表視圖節索引標題 |
否 |
tableView:commitEditingStyle:forRowAtIndexPath: |
void |
為刪除或修改提供資料 |
否 |
UITableViewDelegate :委託協議,主要用來設定表視圖中節頭和節腳的標題,並響應一些動作事件
| 方法 |
傳回型別 |
說明 |
是否需要實現 |
tableView:viewForHeaderInSection: |
UIView * |
為節頭準備自訂視圖,iOS 6之後可以使用 UITableViewHeaderFooterView |
否 |
tableView:viewForFooterInSection: |
UIView * |
為節腳準備自訂視圖,iOS 6之後可以使用 UITableViewHeaderFooterView |
否 |
tableView:didEndDisplayingHeaderView:forSection: |
void |
該方法在節頭從螢幕中消失時觸發(iOS 6之後 的方法) |
否 |
tableView:didEndDisplayingFooterView:forSection: |
void |
當節腳從螢幕中消失時觸發(iOS 6之後的方法) |
否 |
tableView:didEndDisplayingCell:forRowAtIndexPath: |
void |
當儲存格從螢幕中消失時觸發(iOS 6之後的方法) |
否 |
tableView:didSelectRowAtIndexPath: |
void |
響應選擇表視圖儲存格時調用的方法 |
否 |