【问题标题】:UITableView - SelectedBackgroundView not working in iOS7 with Auto-LayoutUITableView - SelectedBackgroundView 在 iOS7 中无法使用自动布局
【发布时间】:2014-06-06 13:34:33
【问题描述】:

我在 iOS7 中使用 UITableVeiw 和静态单元格。在我将故事板转换为使用自动布局之前,表格视图看起来像这样。

我正在使用 tableviewcell 的“背景视图”属性和“selectedBackgroundView”属性来设置背景,如下所示:

在情节提要中启用自动布局后,布局变得疯狂,这就是我剩下的:

我没有遇到任何自动布局问题。只是我不再使用自动布局看到前景和背景。

有什么帮助吗?

【问题讨论】:

  • 尝试重新排列视图。这应该会有所帮助。
  • ^你提出这个建议的理由是什么? DefaultBackgroundView 和 SelectedBackGroundView 不遵循视图层次结构,因为它们不在其中。我还是试过了,还是不行。

标签: ios ipad cocoa-touch uitableview uistoryboard


【解决方案1】:

似乎自动布局给我带来了问题。我以编程方式添加了 backgroundView 和 selectedBackgroundView 并且它可以工作。

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    UIView *selectedView =[UIView new];
    selectedView.backgroundColor=[UIColor colorWithRed:0.604 green:0.812 blue:0.059 alpha:1.000];
    cell.selectedBackgroundView = selectedView;
    UIView *defaultView =[UIView new];
    defaultView.backgroundColor=[UIColor colorWithRed:0.396 green:0.404 blue:0.404 alpha:1.000];
    cell.backgroundView = defaultView;
}

【讨论】:

    【解决方案2】:

    我认为它可以在Storyboard 中修复,但是......“解决方案”完全是愚蠢的:D。如果向selectedBackgroundView 添加宽度和高度约束,它将起作用。该解决方案对我不利,但似乎可行:)

    附:以编程方式添加selectedBackgroundView 的方式也适用于我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-23
      • 1970-01-01
      • 2013-12-17
      • 2013-06-24
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多