Use TableView in IOS to implement the right sliding display selection function _ios

Source: Internet
Author: User

1, in IOS8 before, we realize TableView slide show Delete, top, more and so on the button, all need to implement themselves, in the IOS8 system has been written, as long as a proxy method and a class on the line

2, IOS8 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 often put several buttons to return to the array, the first place into the array of buttons to display at the far right, and finally put the display on the leftmost

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

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 Uitableviewdelegate's

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

Method.

-(Nsarray *) TableView: (UITableView *) TableView Editactionsforrowatindexpath: (Nsindexpath *) IndexPath {if ( indexpath.row==0) {//Add a Delete button deleterowaction = [uitableviewrowaction rowactionwithstyle:
uitableviewrowactionstyledestructive title:@ "Delete" handler:^ (uitableviewrowaction *action, NSIndexPath *indexPath) {
NSLog (@ "Click on Delete");
}]; else if (indexpath.row==1) {//Add a Delete button deleterowaction = [uitableviewrowaction rowactionwithstyle:
uitableviewrowactionstyledestructive title:@ "Delete" handler:^ (uitableviewrowaction *action, NSIndexPath *indexPath) {
NSLog (@ "Click on Delete");
}]; Add a Modify button morerowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@ ' modify '
handler:^ (uitableviewrowaction *action, Nsindexpath *indexpath) {NSLog (@ "clicked on Modify");
Morerowaction.backgroundeffect = [Uiblureffect Effectwithstyle:uiblureffectstyledark]; else if (indexpath.row==2) {//Add a Delete button deleterowaction = [uitableviewrowaction rowactionwithstyle: Uitableviewrowactionstyledestructive title:@ "Delete" handler:^ (uitableviewrowaction *action, Nsindexpath *indexpath) {NSLog (@ "clicked Delete"); Add a Modify button morerowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@ ' modify '
handler:^ (uitableviewrowaction *action, Nsindexpath *indexpath) {NSLog (@ "clicked on Modify");
Morerowaction.backgroundeffect = [Uiblureffect Effectwithstyle:uiblureffectstyledark]; Add a send button sanrowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@ "Send"
handler:^ (uitableviewrowaction *action, Nsindexpath *indexpath) {NSLog (@ "click Send");
Sanrowaction.backgroundcolor=[uicolor Orangecolor]; else{//Add a Delete button deleterowaction = [Uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledestructive
title:@ "Delete" handler:^ (uitableviewrowaction *action, Nsindexpath *indexpath) {NSLog (@ "clicked Delete"); Add a Modify button morerowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@ ' modify ' handler:^ (Uitableviewrowaction *action, Nsindexpath *indexpath) {NSLog (@ "click Modify");
Morerowaction.backgroundeffect = [Uiblureffect Effectwithstyle:uiblureffectstyledark]; Add a send button sanrowaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@ "Send"
handler:^ (uitableviewrowaction *action, Nsindexpath *indexpath) {NSLog (@ "click Send");
Sanrowaction.backgroundcolor=[uicolor Orangecolor]; Add a send button OK = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstylenormal title:@ ' OK key ' handler:^ (
Uitableviewrowaction *action, Nsindexpath *indexpath) {NSLog (@ "click OK");}];
Ok.backgroundcolor=[uicolor Purplecolor]; ///Put the Set button in the array to return if (indexpath.row==0) {returns @[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];} return nil; }

The above is a small set of iOS for you to introduce the use of TableView to achieve the right sliding display selection function of the relevant information, hope to help you.

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.