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