Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS TableView滑动UIContextualAction无法获取正确的图像_Ios_Uitableview_Uicontextualaction_Uiswipeactionsconfiguration - Fatal编程技术网

iOS TableView滑动UIContextualAction无法获取正确的图像

iOS TableView滑动UIContextualAction无法获取正确的图像,ios,uitableview,uicontextualaction,uiswipeactionsconfiguration,Ios,Uitableview,Uicontextualaction,Uiswipeactionsconfiguration,我想在单元格的左侧滑动中设置一个图像,有代码,但不起作用 - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { if (@available (iOS 11, *)) { UIContextualAction *deleteAction = [UICon

我想在单元格的左侧滑动中设置一个图像,有代码,但不起作用

- (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;
}

我知道了


事实上,该图像与左侧的细胞图像相同。怎么了?

检查您的图像。我认为当你滑动选择图像时,单元格正在对图像进行着色。试试这个。。 1.转到xcode中的资产文件夹并选择您的图像。 2.转到右侧的属性检查器,选择“渲染为”选项,然后选择“原始图像”。 3.测试


让我知道这是否有帮助:-)

使用透明背面作为复选标记,因为
UIContextualAction
将图像渲染为模板,因此图像的任何填充区域都将显示为白色

这应该是你的形象:


UIContextualActionStyleNormal
更改为
UIContextualActionStyleNormal