uitableview增加多個左滑選項

今天看我們的項目里有一個用第三方增加多個左滑選項的,他們說UITableView? 實現(xiàn)不了,我不信,然后我就去百度了。

后來發(fā)現(xiàn)百度倒是提到一個8.0以后UITableView增加的api

- (nullable NSArray*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

一句話帶過,也沒有說具體方法,然后我再搜出了第三方就沒有別的了,然后我就自己在UITableView 的代理方法里總結(jié)研究。

效果圖

使用方法如下:

- (nullable NSArray*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

{

NSMutableArray *arrbtn = [[NSMutableArray alloc] init];

NSArray *title = @[@"delect",@"show",@"update"];

NSArray *color = @[[UIColor redColor],[UIColor grayColor],[UIColor greenColor]];

for (int a = 0; a <3; a++) {

UITableViewRowAction *action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:title[a] handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

if (a == 0) {

[self tableView:tableView changeSelectStyle:UITableViewLeftSelectStyleDelect indexPath:indexPath];

}else if (a == 1)

{

[self tableView:tableView changeSelectStyle:UITableViewLeftSelectStyleShow indexPath:indexPath];

}

else if (a ==2)

[self tableView:tableView changeSelectStyle:UITableViewLeftSelectStyleUpdate indexPath:indexPath];

}];

action.backgroundColor = color[a];

[arrbtn addObject:action];

}

return? (NSArray *)arrbtn;

}

這就完成了創(chuàng)建,生成,返回點擊的效果,比第三方簡單多了,我看到在qq上使用的就是這種方法。

如果大家還不知道怎么寫可以參考下demo:多個左滑選項的demo

cocoachina下載路徑:http://code.cocoachina.com/view/135182?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • #pragma mark someValueAboutTableView 1.tableView的樣式:UITab...
    瀟巖閱讀 1,050評論 0 0
  • 1.nav1.navigationBar.barStyle=UIBarStyleBlack; //改變導(dǎo)航欄背景顏...
    SadMine閱讀 1,867評論 1 4
  • 自定義單元格 表格無論有多少中自定義單元格樣式 每一種自定義單元格都有復(fù)用的能力所以每一個單元格都要帶有一個靜態(tài)局...
    DVWang閱讀 317評論 0 0
  • 概述在iOS開發(fā)中UITableView可以說是使用最廣泛的控件,我們平時使用的軟件中到處都可以看到它的影子,類似...
    liudhkk閱讀 9,297評論 3 38
  • 版權(quán)聲明:未經(jīng)本人允許,禁止轉(zhuǎn)載. 1. TableView初始化 1.UITableView有兩種風(fēng)格:UITa...
    蕭雪痕閱讀 2,990評論 2 10

友情鏈接更多精彩內(nèi)容