IOS cell左滑出現多個功能按鈕(IOS8以後支援)

來源:互聯網
上載者:User

標籤:tableview   struct   for   ati   代碼   void   load   wro   調用   


#import "ViewController.h"#import "Swift_OC-Swift.h"@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>@property (weak, nonatomic) IBOutlet UITableView *tableView;@property(nonatomic,strong)NSMutableArray *dataSource;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.dataSource = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",nil]; self.tableView.delegate = self; self.tableView.dataSource = self; // Swift *swift = [[Swift alloc]init]; // //OC調用swift方法("Swift_OC-Swift.h") // [swift demoFunction]; // //swift調用OC方法(Swift_OC-Bridging-Header) // [swift swiftFetctionObjectC];}-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1;}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataSource.count;}-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.textLabel.text = self.dataSource[indexPath.row]; return cell;}/////////////////下面實現相關代碼////////////////////////////-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES;}//返回IOS8之前只能返回一個按鈕//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath//{// return UITableViewCellEditingStyleDelete;//}////-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{// // if (editingStyle ==UITableViewCellEditingStyleDelete) {// [self.dataSource removeObjectAtIndex:indexPath.row];// [self.tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];// }//}//IOS8以後可以返回多個按鈕- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{ //設定刪除按鈕 UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) { [self.dataSource removeObjectAtIndex:indexPath.row]; [self.tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic]; }]; //設定收藏按鈕 UITableViewRowAction *collectRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"收藏" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) { NSLog(@"收藏了"); }]; //設定置頂按鈕 UITableViewRowAction *topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"置頂" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) { [self.dataSource exchangeObjectAtIndex:indexPath.row withObjectAtIndex:0]; NSIndexPath *firstIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section]; [tableView moveRowAtIndexPath:indexPath toIndexPath:firstIndexPath]; }]; //設定置頂按鈕 UITableViewRowAction *testRowAction1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"測試1" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) { NSLog(@"測試1"); }]; UITableViewRowAction *testRowAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"測試2" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) { NSLog(@"測試2"); }]; UITableViewRowAction *testRowAction3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"測試2" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) { NSLog(@"測試3"); }]; collectRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; topRowAction.backgroundColor = [UIColor blueColor]; collectRowAction.backgroundColor = [UIColor grayColor]; //經測試可以返回無限個.... return @[deleteRowAction,collectRowAction,topRowAction,testRowAction1,testRowAction2,testRowAction3];}

 

:

 

 

 

IOS cell左滑出現多個功能按鈕(IOS8以後支援)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.