方法(1)
//左滑事件
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)){
return [UISwipeActionsConfiguration configurationWithActions:[self getActionsWithType:indexPath]];
}
-(NSArray*)getActionsWithType:(NSIndexPath*)indexPath{
RYMFriendModel *model = [[self.letterResultArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
NSArray*titleArrray;
titleArrray = @[@"删除",@"编辑"];
SXWeakSelf
UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:titleArrray[0] handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
NSLog(@"UIContextualAction-删除要实现的代码");
completionHandler(NO);//调用次回调以后,点击以后会回到复原Cell,传YES/NO没有发现区别
}];
UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:titleArrray[1] handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
completionHandler(NO);
}];
action1.backgroundColor= [UIColorcolorWithRed:227/255.0green:90/255.0blue:80/255.0alpha:1];
action2.backgroundColor= [UIColorcolorWithRed:227/255.0green:151/255.0blue:73/255.0alpha:1];
return@[action1,action2];
}
方法(2)
// 允许进入编辑状态
- (BOOL)tableView:(UITableView*)tableViewcanEditRowAtIndexPath:(NSIndexPath*)indexPath{
return Yes;
}
// 自定义cell的编辑模式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
// 进入编辑模式,确定编辑提交操作时,执行的代理方法
- (void)tableView:(UITableView*)tableViewcommitEditingStyle:(UITableViewCellEditingStyle)editingStyleforRowAtIndexPath:(NSIndexPath*)indexPath{
}
方法(3)
- (NSArray*)tableView:(UITableView*)tableVieweditActionsForRowAtIndexPath:(NSIndexPath*)indexPath {
//删除
SXWeakSelf;
UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[weakSelfdealDeteleWith:indexPath];
}];
//编辑
// UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"编辑" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
//
// }];
// return @[deleteRowAction,editRowAction];
return@[deleteRowAction];
}
网友评论