gpt4 book ai didi

ios - 自定义 UITableViewCell 恢复为 selectRowAtIndexPath 的标准蓝色单元格

转载 作者:行者123 更新时间:2023-11-29 13:05:47 24 4
gpt4 key购买 nike

我有一个 UITableViewCell子类,它给我自定义样式和额外数据。

当用户交互时一切正常,但是当我通过调用 selectRowAtIndexPath 以编程方式选择它时,它会恢复为标准选择的带有蓝色背景的 UITableViewCell

这是我的代码

[myTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];

最佳答案

看到这个问题:UITableView Cell selected Color

作为解决方法,您可以覆盖 didSelectRowAtIndexPath 并在那里设置背景颜色:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];

要将 backgroungColor 设置为正常颜色覆盖 didDeselectRowAtIndexPath:

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath  

关于ios - 自定义 UITableViewCell 恢复为 selectRowAtIndexPath 的标准蓝色单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18691837/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com