IOS cell Left slide multiple function buttons (IOS8 support later)

Source: Internet
Author: User


#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 calls the Swift method ("Swift_oc-swift.h")//[Swift demofunction]; Swift calls OC method (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;} The following implementation of the relevant Code////////////////////////////-(BOOL) TableView: (UITableView *) TableView Caneditrowatindexpath: (Nsindexpath *) indexpath{return YES;} Returns only one button before returning IOS8//-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath *) indexpath//{//return uitableviewcelleditingstyledelete;//}////-( void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) indexpath{////if (Editingstyle ==uitableviewcelleditingstyledelete) {//[s Elf.datasource removeobjectatindex:indexpath.row];//[Self.tableview Deleterowsatindexpaths:@[indexpath] Withrowanimation:uitableviewrowanimationautomatic];//}//}//ios8 can return multiple buttons later-(Nsarray *) TableView: (UITableView *) TableView Editactionsforrowatindexpath: (Nsindexpath *) indexpath{//Set Delete button uitableviewrowaction *deleterowaction = [UITable Viewrowaction rowactionwithstyle:uitableviewrowactionstyledestructive title:@ "Delete" handler:^ (UITableViewRowAction * Action,nsindexpath *indexpath) {[Self.datasource removeObjectAtIndex:indexPath.row]; [Self.tableview deleterowsatindexpaths:@[indexpath]withrowanimation:uitableviewrowanimationautomatic]; }]; Set Favorite button Uitableviewrowaction *collectrowaction = [uitableviewrowaction rowactionwithstyle: Uitableviewrowactionstyledefault title:@ "Favorites" handler:^ (uitableviewrowaction *action,nsindexpath *indexPath) {NSLog (@ "collection"); }]; Set the sticky button uitableviewrowaction *toprowaction = [uitableviewrowaction rowactionwithstyle: Uitableviewrowactionstyledefault title:@ "pinned" 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]; }]; Set the sticky button uitableviewrowaction *testrowaction1 = [uitableviewrowaction rowactionwithstyle: Uitableviewrowactionstyledefault title:@ "Test 1" handler:^ (uitableviewrowaction *action,nsindexpath *indexPath) {NSLo G (@ "Test 1"); }]; Uitableviewrowaction *testrowaction2 = [Uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledefault title:@ "Test 2" handler:^ (uitableviewrowaction *action,nsindexpath *indexpath) {NSLog (@ "Test 2"); }]; Uitableviewrowaction *testrowaction3 = [Uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledefault title:@ "Test 2" handler:^ (uitableviewrowaction *action,nsindexpath *indexpath) {NSLog (@ "Test 3"); }]; Collectrowaction.backgroundeffect = [Uiblureffect effecTwithstyle:uiblureffectstylelight]; Toprowaction.backgroundcolor = [Uicolor Bluecolor]; Collectrowaction.backgroundcolor = [Uicolor Graycolor]; The test can return an unlimited number of .... return @[deleterowaction,collectrowaction,toprowaction,testrowaction1,testrowaction2, TestRowAction3];}

:

IOS cell Left slide multiple function buttons (IOS8 support later)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.