我有一个 iOS 应用程序UITableView
,我注意到当用户选择时单元格背景颜色会闪烁白色Delete
button.
In the editActionsForRowAtIndexPath
方法,我创建了两个单元格按钮:Edit
and Delete
。第一个按钮的样式设置为UITableViewRowActionStyleNormal
。然而第二个按钮的样式设置为UITableViewRowActionStyleDestructive
- 我注意到只有当样式设置为破坏性时才会出现此问题。有谁知道为什么会发生这种情况?
这是我用来设置单元格操作按钮的方法:
-(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
按钮,当删除动画发生时,单元格会变成白色。
我怎样才能解决这个问题?
事实证明我遇到的问题是由于 iOS 错误造成的。我在这里找到了解决方案:https://stackoverflow.com/a/46649768/1598906 https://stackoverflow.com/a/46649768/1598906
[[UITableViewCell appearance] setBackgroundColor:[UIColor clearColor]];
上面的代码是在App Delegate中设置的,它将背景颜色设置为clear,从而去除了视图的白色背景。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)