我想在单元格的左侧滑动中设置一个图像,有代码,但它不起作用。
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
if (@available (iOS 11, *)) {
UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
if (self.dataArray.count > indexPath.row) {
[self.dataArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
completionHandler(YES);
}];
deleteAction.backgroundColor = [UIColor blueColor];
UIContextualAction *backAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:nil handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
// 不做任何事
[tableView setEditing:NO animated:YES];
completionHandler(YES);
}];
backAction.image = [UIImage imageNamed:@"public_system_success"];
UISwipeActionsConfiguration *configuration = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction, backAction]];
return configuration;
}
return nil;
}
我得到了这个向左滑动的菜单
实际上,该图像与左侧的单元格图像相同。怎么了?