gpt4 book ai didi

objective-c - UIView背景色不生效

转载 作者:行者123 更新时间:2023-12-01 19:23:31 34 4
gpt4 key购买 nike

有人可以告诉我为什么这不起作用吗?

我的表格 View 单元格中有以下这些代码行,用于 tableView:didSelectAtIndexRowPath:方法。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[tableView viewWithTag:199]removeFromSuperview];

CGSize cellSize = [tableView cellForRowAtIndexPath:indexPath].frame.size;

UIView *subSelectionView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, (int)cellSize.width - 20, 100)];

[subSelectionView setBackgroundColor:[UIColor blueColor]];

subSelectionView.layer.borderColor = [UIColor grayColor].CGColor;
subSelectionView.layer.borderWidth = 1;

subSelectionView.tag = 199;

[[tableView cellForRowAtIndexPath:indexPath]addSubview:subSelectionView];
}

注意代码:
[subSelectionView setBackgroundColor:[UIColor  blueColor]];

显然,我想更改添加到 UITableViewCell 的 subview 的颜色。但为什么它不工作?

最佳答案

在表格上添加 subview 后重新加载表格

[[tableView cellForRowAtIndexPath:indexPath]addSubview:subSelectionView];

[tableview reloadData];

关于objective-c - UIView背景色不生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9074608/

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