溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

UITableViewCell兩個(gè)協(xié)議 UITableViewDelegate 和 UITableViewDataSource

發(fā)布時(shí)間:2020-08-05 09:42:18 來源:網(wǎng)絡(luò) 閱讀:2070 作者:yjf123546 欄目:開發(fā)技術(shù)


一, UITableViewDataSource

1,必須實(shí)現(xiàn) 設(shè)置每個(gè)分區(qū)的行數(shù)

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

2,必須實(shí)現(xiàn), 設(shè)置每個(gè)分區(qū)的cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

3,設(shè)置分區(qū)
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

4,為每個(gè)分區(qū)設(shè)置標(biāo)題
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

5,為分區(qū)設(shè)置索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

6,設(shè)置tableView每行的編輯狀態(tài)
- (BOOL)tableView:(UITableView *)tableView canEditRowA tIndexPath:(NSIndexPath *)indexPath

7,當(dāng)提交編輯操作時(shí)觸發(fā)(插入或刪除)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

8,設(shè)置tableView每一個(gè)cell是否允許移動(dòng)
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

9,提交移動(dòng)操作之后觸發(fā)
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

二, UITableViewDelegate


10,設(shè)置行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

11,設(shè)置cell選中的事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath


12,設(shè)置tableViewCell的編輯樣式
設(shè)置tableViewCell的編輯樣式(插入刪除) - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

13,設(shè)置當(dāng)點(diǎn)擊刪除按鈕時(shí)提示的確認(rèn)文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0)

14,設(shè)置cell的移動(dòng)位置
設(shè)置cell移動(dòng)的位置, - (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{    //現(xiàn)在移動(dòng)時(shí)只能在本區(qū)內(nèi)移動(dòng)    //sourceIndexPath 原地址    //proposedDestinationIndexPath將要移動(dòng)到的地址    if (sourceIndexPath.section == proposedDestinationIndexPath.section) {        //如果是同一個(gè)分區(qū),返回目的地址        return proposedDestinationIndexPath;    }        //如果不是同一個(gè)分區(qū),返回原來的地址    return sourceIndexPath;    }

三,處理編輯操作詳細(xì)步驟

 1,tableView 進(jìn)入編輯狀態(tài) 方法(-(void)setEditing:(BOOL)editing animated:(BOOL)animated)  2,設(shè)置每一行的編輯狀態(tài) 方法(- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath)  3,設(shè)置每一行的編輯樣式(可選) 方法(- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath)  4,處理編輯操作(插入/刪除) 方法(- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath)

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI