一, UITableViewDataSource
1,必須實現 設置每個分區的行數
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
2,必須實現, 設置每個分區的cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
3,設置分區
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
4,爲每個分區設置標題
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
5,爲分區設置索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
6,設置tableView每行的編輯狀態
- (BOOL)tableView:(UITableView *)tableView canEditRowA tIndexPath:(NSIndexPath *)indexPath
7,當提交編輯操作時觸發(插入或刪除)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
8,設置tableView每一個cell是否允許移動
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
9,提交移動操作之後觸發
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
二, UITableViewDelegate
10,設置行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
11,設置cell選中的事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
12,設置tableViewCell的編輯樣式
設置tableViewCell的編輯樣式(插入刪除) - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
13,設置當點擊刪除按鈕時提示的確認文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0)
14,設置cell的移動位置
設置cell移動的位置, - (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{ //現在移動時只能在本區內移動 //sourceIndexPath 原地址 //proposedDestinationIndexPath將要移動到的地址 if (sourceIndexPath.section == proposedDestinationIndexPath.section) { //如果是同一個分區,返回目的地址 return proposedDestinationIndexPath; } //如果不是同一個分區,返回原來的地址 return sourceIndexPath; }
三,處理編輯操作詳細步驟
1,tableView 進入編輯狀態 方法(-(void)setEditing:(BOOL)editing animated:(BOOL)animated) 2,設置每一行的編輯狀態 方法(- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath) 3,設置每一行的編輯樣式(可選) 方法(- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath) 4,處理編輯操作(插入/刪除) 方法(- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath)
UITableViewCell兩個協議 UITableViewDelegate 和 UITableViewDataSource
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.