IOS TableView Right Slide display selection

Source: Internet
Author: User

How do I use uitableviewrowaction to achieve right-slip selection?

1, before iOS8, we realize tableview in the sliding display delete, top, more and so on the button, all need to achieve their own, in the IOS8 system has been written, as long as a proxy method and a class on the line

2, iOS8 the protocol to a method, the return value is an array of Tableview:editactionforrowatindexpath: method, we can write several buttons inside the method, and then put in the array to return, The class of those buttons is uitableviewrowaction.

3, in the uitableviewrowaction class. We can set the style of the button, display text, background color and button events (implemented within the block)

4, in the proxy method, we can common more than one button to return in the array, the first button to put the array is displayed on the far right, the last put in the display on the leftmost

5, if you set one or more buttons, the system comes with the Delete button disappears

Set TableView to edit

-(BOOL) TableView: (UITableView *) TableView Shouldindentwhileeditingrowatindexpath: (Nsindexpath *) Indexpath

{

return YES;

}

How to use Uitableviewrowaction:

+ (Instancetype) Rowactionwithstyle: (uitableviewrowactionstyle) style title: (Nullable NSString *) title handler: (Void ( ^) (uitableviewrowaction *action, Nsindexpath *indexpath)) handler;

Rewrite the uitableviewdelegate

-(Nullable nsarray<uitableviewrowaction *> *) TableView: (UITableView *) TableView Editactionsforrowatindexpath :(Nsindexpath *) Indexpath

Method.

-(Nsarray *) TableView: (UITableView *) TableView Editactionsforrowatindexpath: (Nsindexpath *) indexpath{if(indexpath.row==0){        //Add a Delete buttonDeleterowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledestructive title:@"Delete"handler:^ (uitableviewrowaction *action, Nsindexpath *Indexpath) {NSLog (@"Click the Delete");            }]; }    Else if(indexpath.row==1){        //Add a Delete buttonDeleterowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledestructive title:@"Delete"handler:^ (uitableviewrowaction *action, Nsindexpath *Indexpath) {NSLog (@"Click the Delete");                }]; //Add a Modify buttonMorerowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@"Modify"handler:^ (uitableviewrowaction *action, Nsindexpath *Indexpath) {NSLog (@"Click the edit");        }]; Morerowaction.backgroundeffect=[Uiblureffect Effectwithstyle:uiblureffectstyledark]; }    Else if(indexpath.row==2){        //Add a Delete buttonDeleterowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledestructive title:@"Delete"handler:^ (uitableviewrowaction *action, Nsindexpath *Indexpath) {NSLog (@"Click the Delete");                }]; //Add a Modify buttonMorerowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@"Modify"handler:^ (uitableviewrowaction *action, Nsindexpath *Indexpath) {NSLog (@"Click the edit");        }]; Morerowaction.backgroundeffect=[Uiblureffect Effectwithstyle:uiblureffectstyledark]; //Add a Send buttonsanrowaction= [Uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@"Send"handler:^ (uitableviewrowaction *action, Nsindexpath *Indexpath) {NSLog (@"Click the Send");        }]; Sanrowaction.backgroundcolor=[Uicolor Orangecolor]; }    Else{        //Add a Delete buttonDeleterowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledestructive title:@"Delete"handler:^ (uitableviewrowaction *action, Nsindexpath *Indexpath) {NSLog (@"Click the Delete");                }]; //Add a Modify buttonMorerowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@"Modify"handler:^ (uitableviewrowaction *action, Nsindexpath *Indexpath) {NSLog (@"Click the edit");        }]; Morerowaction.backgroundeffect=[Uiblureffect Effectwithstyle:uiblureffectstyledark]; //Add a Send buttonsanrowaction= [Uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@"Send"handler:^ (uitableviewrowaction *action, Nsindexpath *Indexpath) {NSLog (@"Click the Send");        }]; Sanrowaction.backgroundcolor=[Uicolor Orangecolor]; //Add a Send buttonOK= [Uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@"OK key"handler:^ (uitableviewrowaction *action, Nsindexpath *Indexpath) {NSLog (@"clicked OK.");        }]; Ok.backgroundcolor=[Uicolor Purplecolor]; }            //put the Set button in the array to return    if(indexpath.row==0) {        return@[deleterowaction]; }Else if(indexpath.row==1){        return@[deleterowaction,morerowaction]; }Else if(indexpath.row==2){        return@[deleterowaction,morerowaction,sanrowaction]; }Else if(indexpath.row==3){        return@[deleterowaction,morerowaction,sanrowaction,ok]; }    returnNil;}

IOS TableView Right Slide display selection

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.