删除单元格时,表格视图单元格背景变为白色-iOS [英] Table view cell background goes white when deleting a cell - iOS

查看:143
本文介绍了删除单元格时,表格视图单元格背景变为白色-iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带UITableView的iOS应用,我注意到当用户选择Delete按钮时,单元格背景颜色会闪烁白色.

I have an iOS app with a UITableView, I have noticed that the cell background colour flashes white when the user selects the Delete button.

editActionsForRowAtIndexPath方法中,我创建了两个单元格按钮:EditDelete.第一个按钮的样式设置为UITableViewRowActionStyleNormal.但是,第二个按钮的样式设置为UITableViewRowActionStyleDestructive-我注意到仅当将样式设置为破坏性时才会出现此问题.有人知道为什么会这样吗?

In the editActionsForRowAtIndexPath method, I have created two cell buttons: Edit and Delete. The first button's style is set to UITableViewRowActionStyleNormal. however the second button's style is set to UITableViewRowActionStyleDestructive - I have noticed that this issue only occurs when then style is set to destructive. Does anyone know why this is happening?

这是我用来设置单元格操作按钮的方法:

Here is the method I am using to set the cell action buttons:

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

    // Create the table view cell edit buttons.
    UITableViewRowAction *editButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

        // Edit the selected action.
        [self editAction:indexPath];
    }];
    editButton.backgroundColor = [UIColor blueColor];

    UITableViewRowAction *deleteButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

        // Delete the selected action.
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }];

    return @[deleteButton, editButton];
}

当用户滚动,点按它或选择Edit按钮时,该单元格的颜色是正常的,但是当他们选择Delete按钮时,该单元格会在发生删除动画时变为白色

The colour of the cell is normal when the user is scrolling, tapping it or when he/she selects the Edit button, but when they select the Delete button, the cell turns white as the deletion animation is occurring.

我该如何解决?

谢谢您的时间,丹.

推荐答案

事实证明,我遇到的问题是由于iOS错误引起的.我在这里找到了解决方案: https://stackoverflow.com/a/46649768/1598906

It turns out the issue I am experiencing, is due to an iOS bug. I found a solution here: https://stackoverflow.com/a/46649768/1598906

[[UITableViewCell appearance] setBackgroundColor:[UIColor clearColor]];

上面的代码在App Delegate中设置,将背景颜色设置为清除,从而删除了白色背景视图.

The above code is set in the App Delegate, it set the background color to clear, thus removing the white background view.

这篇关于删除单元格时,表格视图单元格背景变为白色-iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆