仍是使用系統(tǒng)的框架方法,我自己有嘗試使用給cell添加手勢(shì),在cell的底層添加一些操作的入口,但是沒有實(shí)現(xiàn)出來,有實(shí)現(xiàn)出來的大神,可以留下鏈接~
cell底部的功能入口
使用系統(tǒng)的方式建立左滑的功能
// 設(shè)置的cell為編輯效果
cell.editingAccessoryType = UITableViewCellAccessoryDetailButton;
#pragma mark - tableView自帶的編輯功能
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
KTLog(@"標(biāo)記為已回訪");
}
}
// 選擇編輯的樣式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
// 修改delete的文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"標(biāo)記為\n已回訪";
}
// 設(shè)置顯示多個(gè)按鈕
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
// UITableViewRowAction 通過此類創(chuàng)建按鈕
/*
* 1. 我們?cè)谑褂靡恍?yīng)用的時(shí)候,在滑動(dòng)一些聯(lián)系人的某一行的時(shí)候,會(huì)出現(xiàn)刪除、置頂、更多等等的按鈕,在iOS8之前,我們都需要自己去實(shí)現(xiàn)。到了iOS8,系統(tǒng)已經(jīng)寫好了,只需要一個(gè)代理方法和一個(gè)類就搞定了
* 2. iOS8的協(xié)議多了一個(gè)方法,返回值是數(shù)組的tableView:editActionsForRowAtIndexPath:方法,我們可以在方法內(nèi)部寫好幾個(gè)按鈕,然后放到數(shù)組中返回,那些按鈕的類就是UITableViewRowAction
* 3. 在UITableViewRowAction類,我們可以設(shè)置按鈕的樣式、顯示的文字、背景色、和按鈕的事件(事件在Block中實(shí)現(xiàn))
* 4. 在代理方法中,我們可以創(chuàng)建多個(gè)按鈕放到數(shù)組中返回,最先放入數(shù)組的按鈕顯示在最右側(cè),最后放入的顯示在最左側(cè)
* 5. 注意:如果我們自己設(shè)定了一個(gè)或多個(gè)按鈕,系統(tǒng)自帶的刪除按鈕就消失了...
*/
UITableViewRowAction * deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
}];
deleteRowAction.backgroundColor = [UIColor redColor];
UITableViewRowAction * topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"置頂" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
}];
topRowAction.backgroundColor = [UIColor blueColor];
UITableViewRowAction * moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
}];
return @[deleteRowAction,topRowAction,moreRowAction];
}
左滑操作