UITableView - SelectedBackgroundView not working in iOS7 with Auto-Layout

谁说胖子不能爱 提交于 2020-01-03 03:22:49

问题


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

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

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.

Any help?


回答1:


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



回答2:


I think it can be fixed in Storyboard but... the "solution" is totally stupid :D. If add width and height constraint to selectedBackgroundView it will works. This solution isn't good for me, but seems like it works :)

P.S. The way with adding selectedBackgroundView programmatically is work for me too.



来源:https://stackoverflow.com/questions/23215150/uitableview-selectedbackgroundview-not-working-in-ios7-with-auto-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!