gpt4 book ai didi

ios - 在界面生成器中更改 UITableViewCell 背景颜色

转载 作者:行者123 更新时间:2023-12-01 18:23:16 25 4
gpt4 key购买 nike

我尽量避免在我的 iOS 项目中添加任何与视觉设置有关的代码,因为这是 Interface Builder 应该为您简化的。

所以我尝试在 IB 中设置原型(prototype)单元,然后调用:

TableCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"TableCell"];

问题是如果我在 IB 中更改单元格的背景颜色,当我运行我的应用程序时它仍然是白色。我可以很好地预设标签的颜色,但不能预设表格单元格中的背景颜色属性。

作为附加说明,我可以看到在初始化变量后断点和检查变量后,作为单元格内 backgroundView 的 UIView 为 null。

更新我的印象是 IB 中的背景颜色选项基本上没有用?我宁愿不相信。

最佳答案

不幸的是,你不能那样做。

更改 tableView:willDisplayCell:forRowAtIndexPath: 中单元格的背景颜色

来自 UITableViewCell 的文档:

Note: If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source. Changes to the background colors of cells in a group-style table view has an effect in iOS 3.0 that is different than previous versions of the operating system. It now affects the area inside the rounded rectangle instead of the area outside of it.

关于ios - 在界面生成器中更改 UITableViewCell 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15790518/

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