IOS tableView right slide display selection, iostableview right slide

Source: Internet
Author: User

IOS tableView right slide display selection, iostableview right slide

How to Use UITableViewRowAction to achieve right-slide selection?

1. Before iOS8, we had to implement the sliding display deletion, pin to top, More and other buttons in tableview by ourselves. The system has been written in ios8, you only need one proxy method and one class.

2. The iOS8 Protocol has a correct method. The returned value is the tableview of the array: editActionForRowAtIndexPath: method. We can write several buttons in the method and put them in the array to return the result. The classes of those buttons are UITableviewRowAction.

3. In the UITableviewRowAction class. We can set the button style to display text, background color, and button events (implemented within the block)

4. In the proxy method, we can usually put multiple buttons into an array to return the results. The buttons placed first in the array are displayed on the rightmost side, and the buttons placed last are displayed on the leftmost side.

5. If you set one or more buttons, the deletion button that comes with the system disappears.

 

You can edit tableView settings.

-(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;

 

Override 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 to delete") ;}] ;}else if (indexPath. row = 1) {// Add a delete button deleteRowAction = [UITableViewRowAction rowActionWithStyle: UITableViewRowActionStyleDestructive title: @ "delete" handler: ^ (UITableViewRowAction * action, NSIndexPath * indexPath) {NSLog (@ "deleted") ;}]; // Add a modify button moreRowAction = [UITableViewRowAction rowActionWithStyle: UITableViewRowActionStyleNormal title: @ "modify" handler: ^ (UITableViewRowAction * action, NSIndexPath * indexPath) {NSLog (@ "click to 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 (@ "deleted") ;}]; // Add a modify button moreRowAction = [UITableViewRowAction rowActionWithStyle: UITableViewRowActionStyleNormal title: @ "modify" handler: ^ (UITableViewRowAction * action, NSIndexPath * indexPath) {NSLog (@ "click to modify") ;}]; moreRowAction. backgroundEffect = [transfermediatwithstyle: Upload]; // Add a send button sanRowAction = [UITableViewRowAction rowActionWithStyle: Sent title: @ "send" handler: ^ (UITableViewRowAction * action, NSIndexPath * indexPath) {NSLog (@ "click to send") ;}]; sanRowAction. backgroundColor = [UIColor orangeColor];} else {// Add a delete button deleteRowAction = [UITableViewRowAction rowActionWithStyle: deleting title: @ "delete" handler: ^ (UITableViewRowAction * action, NSIndexPath * indexPath) {NSLog (@ "deleted") ;}]; // Add a modify button moreRowAction = [UITableViewRowAction rowActionWithStyle: UITableViewRowActionStyleNormal title: @ "modify" handler: ^ (UITableViewRowAction * action, NSIndexPath * indexPath) {NSLog (@ "click to modify") ;}]; moreRowAction. backgroundEffect = [transfermediatwithstyle: Upload]; // Add a send button sanRowAction = [UITableViewRowAction rowActionWithStyle: Sent title: @ "send" handler: ^ (UITableViewRowAction * action, NSIndexPath * indexPath) {NSLog (@ "click to send") ;}]; sanRowAction. backgroundColor = [UIColor orangeColor]; // Add a send button OK = [UITableViewRowAction rowActionWithStyle: blank title: @ "OK key" handler: ^ (UITableViewRowAction * action, NSIndexPath * indexPath) {NSLog (@ "Click OK") ;}]; OK. backgroundColor = [UIColor purpleColor];} // put the set button in the array and 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];} return nil ;}

 

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.