iOS project development Tips (iii)--uitableview implement custom functions such as cell left-stroke deletion

Source: Internet
Author: User

Today to introduce the iOS development in the UITableView cell left-stroke implementation of the top, delete and other functions. This feature requires a very complex implementation before iOS8.0, but there should be a ready-made demo on GitHub, but today is about Apple's new API after iOS8.0 to implement cell-left-stroke custom controls.
1. First create the UITableView view, implement the two agents, Uitableviewdelegate and Uitableviewdatasource, where the code is not said, mainly two callback methods
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
And-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
2. Then implement another proxy method
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
editingStyle = UITableViewCellEditingStyleDelete;//此处的EditingStyle可等于任意UITableViewCellEditingStyle,该行代码只在iOS8.0以前版本有作用,也可以不实现。
}

3. Re-implementation
'-(Nsarray) TableView: (UITableView) TableView Editactionsforrowatindexpath: (Nsindexpath *) Indexpath
{
Uitableviewrowaction *deleterowaction = [uitableviewrowaction rowactionwithstyle: uitableviewrowactionstyledestructive title:@ "Delete" handler:^ (uitableviewrowaction *action, NSIndexPath *indexPath) {// Title can be self-defined
NSLog (@ "Click to delete");
}];//here is iOS8.0 after Apple's latest api,uitableviewrowaction,style is the definition of the state defined by the label color, which can also be defined by itself

UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"编辑" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {}];editRowAction.backgroundColor = [UIColor colorWithRed:0 green:124/255.0 blue:223/255.0 alpha:1];//可以定义RowAction的颜色 return @[deleteRoWAction, editRowAction];//最后返回这俩个RowAction 的数组

}`
This achieves the following effect

Also attached:
iOS8.0 Previous demo reference for UITableViewCell left stroke multiple labels

iOS project development Tips (iii)--uitableview implement custom functions such as cell left-stroke deletion

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.