欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS 中使用tableView實現右滑顯示選擇功能

 更新時間:2016年07月24日 11:24:38   作者:鴻鵠當高遠  
這篇文章主要介紹了iOS 中使用tableView實現右滑顯示選擇功能的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

1、在iOS8以前,我們實現tableview中滑動顯示刪除,置頂,更多等等的按鈕時,都需要自己去實現,在iOS8中系統已經寫好了,只要一個代理方法和一個類就行了

2、iOS8的協議對了一個方法,返回值是數組的tableview:editActionForRowAtIndexPath:方法,我們可以在方法內部寫好幾個按鈕,然后放到數組中返回,那些按鈕的類就是UITableviewRowAction

3、在UITableviewRowAction類。我們可以設置按鈕的樣式,顯示文字、背景色和按鈕事件(在block內實現)

4、在代理方法中,我們可以常見多個按鈕放到數組中返回,最先放入數組的按鈕顯示在最右邊,最后放入的顯示在最左邊

5、如果自己設定一個或多個按鈕,系統自帶的刪除按鈕就消失了

設置tableView可以編輯

- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}

UITableViewRowAction的使用方法:

+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(nullable NSString *)title handler:(void (^)(UITableViewRowAction *action, NSIndexPath *indexPath))handler;

重寫UITableViewDelegate的

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

方法。

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0){
// 添加一個刪除按鈕
deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點擊了刪除");
}];
}
else if (indexPath.row==1){
// 添加一個刪除按鈕
deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點擊了刪除");
}];
// 添加一個修改按鈕
moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"修改" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點擊了修改");
}];
moreRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
}
else if (indexPath.row==2){
// 添加一個刪除按鈕
deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點擊了刪除");
}];
// 添加一個修改按鈕
moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"修改" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點擊了修改");
}];
moreRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
// 添加一個發(fā)送按鈕
sanRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"發(fā)送" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點擊了發(fā)送");
}];
sanRowAction.backgroundColor=[UIColor orangeColor];
}
else{
// 添加一個刪除按鈕
deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點擊了刪除");
}];
// 添加一個修改按鈕
moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"修改" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點擊了修改");
}];
moreRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
// 添加一個發(fā)送按鈕
sanRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"發(fā)送" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點擊了發(fā)送");
}];
sanRowAction.backgroundColor=[UIColor orangeColor];
// 添加一個發(fā)送按鈕
OK = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"OK鍵" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點擊了OK");
}];
OK.backgroundColor=[UIColor purpleColor];
}
// 將設置好的按鈕放到數組中返回
if (indexPath.row==0) {
return @[deleteRowAction];
}else if (indexPath.row==1){
return @[deleteRowAction,moreRowAction];
}else if(indexPath.row==2){
return @[deleteRowAction,moreRowAction,sanRowAction];
}else if(indexPath.row==3){
return @[deleteRowAction,moreRowAction,sanRowAction,OK];
}
return nil;
}

以上所述是小編給大家介紹的iOS 中使用tableView實現右滑顯示選擇功能的相關資料,希望對大家有所幫助。

相關文章

  • IOS開發(fā) UIAlertController詳解及實例代碼

    IOS開發(fā) UIAlertController詳解及實例代碼

    這篇文章主要介紹了 IOS開發(fā) UIAlertController詳解及實例代碼的相關資料,需要的朋友可以參考下
    2016-12-12
  • iOS中block變量捕獲原理詳析

    iOS中block變量捕獲原理詳析

    這篇文章主要給大家介紹了關于iOS中block變量捕獲原理的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。
    2017-12-12
  • IOS App 無代碼入侵的方法hook詳細介紹

    IOS App 無代碼入侵的方法hook詳細介紹

    這篇文章主要介紹了IOS App 無代碼入侵的方法hook詳細介紹的相關資料,需要的朋友可以參考下
    2016-12-12
  • 12個iOS技術面試題及答案總結

    12個iOS技術面試題及答案總結

    這篇文章給大家總結了在iOS面試的時候可能會遇到的12個技術面試題,以及這些面試題但答案,這些答案只是給大家一些參考,大家可以再結合自己理解進行回答,有需要的朋友們下面來一起看看吧。
    2016-09-09
  • iOS開發(fā)中使app獲取本機通訊錄的實現代碼實例

    iOS開發(fā)中使app獲取本機通訊錄的實現代碼實例

    這篇文章主要介紹了iOS開發(fā)中使app獲取本機通訊錄的實現代碼實例,主要用到了AddressBook.framework和AddressBookUI.framework,代碼基于傳統的Objective-C,需要的朋友可以參考下
    2016-01-01
  • iOS的UI開發(fā)中Button的基本編寫方法講解

    iOS的UI開發(fā)中Button的基本編寫方法講解

    這篇文章主要介紹了iOS的UI開發(fā)中Button的基本編寫方法講解,代碼基于傳統的Objective-C,需要的朋友可以參考下
    2015-11-11
  • iOS毛玻璃效果的實現及圖片模糊效果的三種方法

    iOS毛玻璃效果的實現及圖片模糊效果的三種方法

    App設計時往往會用到一些模糊效果或者毛玻璃效果,iOS目前已提供一些模糊API可以讓我們方便是使用,本文給大家介紹iOS毛玻璃效果的實現及圖片模糊效果的三種方法,感興趣的朋友一起學習吧
    2016-01-01
  • IOS代碼筆記之網絡嗅探功能

    IOS代碼筆記之網絡嗅探功能

    這篇文章主要為大家詳細介紹了IOS網絡嗅探功能實現代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • IOS10 相冊相機閃退bug解決辦法

    IOS10 相冊相機閃退bug解決辦法

    這篇文章主要介紹了IOS10 相冊相機閃退bug解決辦法的相關資料,需要的朋友可以參考下
    2016-12-12
  • IOS開發(fā)之多線程NSThiread GCD NSOperation Runloop

    IOS開發(fā)之多線程NSThiread GCD NSOperation Runloop

    這篇文章主要介紹了IOS多線程開發(fā),主要用到NSThiread、GCD、 NSOperation、Runloop,有詳細的原理解析和實例代碼,對多線程感興趣的同學,可以參考下
    2021-04-04

最新評論