UITableView – SelectedBackgroundView在iOS7中无法使用自动布局
我在iOS7中使用UITableVeiw和静态单元格。 在我将故事板转换为使用自动布局之前,表格视图看起来像这样。
我正在使用tableviewcell的“background view”属性和“selectedBackgroundView”属性来设置背景,如下所示:
在故事板中启用自动布局后,布局变得疯狂,这就是我剩下的:
我没有提交给我的任何自动布局问题。 只是我没有看到自动布局的前景和背景。
有帮助吗?
好像自动布局给我带来了麻烦。 我以编程方式添加了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; }
我认为它可以在Storyboard
中修复但是……“解决方案”完全是愚蠢的:D。 如果向selectedBackgroundView
添加宽度和高度约束,它将起作用。 这个解决方案对我不好,但看起来很有效:)
PS以编程方式添加selectedBackgroundView
的方式也适用于我。