Swift projects use Swtableviewcell

Source: Internet
Author: User
Tags uikit

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

Related Article

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.