The function of the Swtableviewcell is to add the Tableviewcell slide button (including the left and right slide buttons) Project address: Https://github.com/CEWendel/SWTableViewCell It was written in OC, Can be installed with pod or directly into the project, but if it is a swift project, there are some other libraries installed in the pod, there may be a compilation problem, so here I do not use the pod, directly into the project: 1 Downloads Swtableviewcell Project Code 2 Copy the Project class file (under the Podfiles folder) into your Swift project: Add #import "Swtableviewcell" in the project bridging file (bridging-header.h) (there is a problem with compiling here, " Nsmutablearray+swutilitybutton.h "will compile an error, probably because of the lack of reference #import <UIKit/UIkit.h>, add the following is OK) 4 Below you can use Swtableviewcell to let your own Tableviewcell inherit from Swtableviewcell such as want to add the right side of the slide button "modify" to add a method in Tableviewcell
Func addswiperightbuttons ()-void{ var rightbuttons: [Anyobject] = [Anyobject] () var DeleteButton = Uibutto N () deletebutton.backgroundcolor = ZMColor.CellEdit.toUIColor () Deletebutton.settitlecolor ( Uicolor.whitecolor (), forstate:. Normal) deletebutton.settitle ("Modify", Forstate:. Normal) Deletebutton.titlelabel?. Adjustsfontsizetofitwidth = True rightbuttons.append (deletebutton) self.rightutilitybuttons = rightButtons }
Then return false in the Caneditrowatindexpath method in uitableviewdelegate to suppress a delete option that comes with the system At the same time, cell.delegate = self in Cellforrowatindexpath and implement Swtableviewcell delegate
Extension viewcontroller:swtableviewcelldelegate{ func Swipeabletableviewcell (cell:swtableviewcell!, Didtriggerrightutilitybuttonwithindex index:int) { switch index{case 0: uialertview (title: "Notification", Message: "Clicked on the Modify button", Delegate:nil, Cancelbuttontitle: "OK"). Show () Break default: Break }
(Note: Because Tableviewcell inherits the Swtableviewcell, if you add a delegate to your Tableviewcell, the name cannot be called "delegate". Because the Swtableviewcell itself has one, this will compile an error)
Swift projects use Swtableviewcell