標籤: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以後支援)