【问题标题】:Table View Cell Default Background Color - what sets the default colour?表格视图单元格默认背景颜色 - 什么设置默认颜色?
【发布时间】:2014-04-05 13:42:47
【问题描述】:

当我加载 TableView 时,突出显示的单元格的默认单元格背景颜色为浅灰色。 如何以及在何处将其更改为另一种颜色?

【问题讨论】:

  • 您是从 nib 加载还是通过您尝试创建单元格的实例?
  • 你扫描过文档中的UITableViewCell吗?
  • 稍后会处理这些 - 非常感谢 - 这是突出显示的颜色而不是一般背景。当我按下一个单元格时,我可以使用 UIView *selectionView = [[UIView alloc] init]; 之类的代码来指示它。 selectionView.backgroundColor = [UIColor greenColor]; cell.selectedBackgroundView = selectionView;但它是第一次加载它默认为灰色。

标签: ios tableview cell


【解决方案1】:

为方法中的单元格设置 selectionStyle:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

// Code to initialize your cell
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    return cell;

}

【讨论】:

    【解决方案2】:

    我们可以在这个方法中设置选中的backgroundView

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    用这些线

    UIView *selectionView = [[UIView alloc] init];
    selectionView.backgroundColor = [UIColor greenColor];
    cell.selectedBackgroundView = selectionView;
    

    【讨论】:

    • 否 - 当您在页面加载后移动单元格焦点时,该例程可以正常工作。我的问题是如何在页面加载时更改所选单元格的背景颜色。默认是灰色的,我想把它改成黄色。
    • 变得混乱: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 在页面加载时绘制屏幕 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath :(NSIndexPath *)indexPath 每次按下一个新单元格时都会处理。道歉
    猜你喜欢
    • 2011-10-09
    • 2016-05-24
    • 2014-11-03
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 2013-11-19
    • 1970-01-01
    • 2013-03-11
    相关资源
    最近更新 更多