The cell Multi-button for iOS development

Source: Internet
Author: User

iOS development often occurs when a cell requires multiple buttons, which are generally thought to be imported into a third-party framework. But in fact, after iOS 8, the system provides uitableviewrowaction and a new delegate approach, making it easy to customize some operations. Buttons such as top, delete, modify, more, favorites, etc.

-(Nsarray *) TableView: (UITableView *) TableView Editactionsforrowatindexpath: (Nsindexpath *) indexpath{

Add a sticky button

Uitableviewrowaction *toprowaction = [Uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledefault title:@ "pinned" handler:^ (uitableviewrowaction *action, Nsindexpath *indexpath) {

NSLog (@ "Click on the top button");

1. Update data

[_diarary ExchangeObjectAtIndex:indexPath.row withobjectatindex:0];

2. Update UI

Nsindexpath *firstindexpath = [Nsindexpath indexpathforrow:0 inSection:indexPath.section];

[TableView Moverowatindexpath:indexpath Toindexpath:firstindexpath];

}];

Toprowaction.backgroundcolor = [uicolor redcolor];//customizable button color

}

This allows you to add any number of buttons. To make sure this code takes effect, you also need to implement the Commiteditingstyle delegate method, even if nothing is written.

-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) indexpath{

}

Remember: When you add multiple groups of buttons, the system comes with a delete button that does not exist and you need to rewrite it yourself.

The cell Multi-button for iOS development

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.