UITableView-SelectedBackgroundView在带有自动布局的iOS7中不起作用 [英] UITableView - SelectedBackgroundView not working in iOS7 with Auto-Layout

查看:115
本文介绍了UITableView-SelectedBackgroundView在带有自动布局的iOS7中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将UITableVeiw与iOS7中的静态单元格一起使用。在我将情节提要板转换为使用自动布局之前,表格视图看起来像这样。

I am using UITableVeiw with static cells in iOS7. The table view looked like this before I converted my storyboard to use autolayouts.

我正在使用tableviewcell的 background view属性和 selectedBackgroundView属性来设置背景,如下所示:

I am using the "background view" property and the "selectedBackgroundView" property of the tableviewcell to set backgrounds like so:

< img src = https://i.stack.imgur.com/YqJjv.png alt =在此处输入图片描述>

虽然启用了自动布局在情节提要中,布局变得井井有条,这就是我剩下的:

After enabling auto-layout though in the storyboard, the layout goes bonkers and this is what I am left with:

我没有呈现给我的任何自动布局问题。只是我不再通过自动版式看到前景和背景了。

I don't have any auto-layout issues that are presented to me. Just that I am not seeing the foreground and background anymore with auto-Layouts.

有帮助吗?

推荐答案

好像是自动布局给我制造麻烦我以编程方式添加了backgroundView和selectedBackgroundView,并且可以正常工作。

Seems like the auto-layout was creating problems for me. I added the backgroundView and selectedBackgroundView programmatically and it works.

- (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;
}

这篇关于UITableView-SelectedBackgroundView在带有自动布局的iOS7中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆