iOS 8 gray box over UITableView

2019-04-05 08:16发布

I am making an app where I need to use UITableViews to display content in an organized fashion, but since I updated to iOS 8 and Xcode 6 I have been getting a mystery gray box over almost the entire view. This can be seen in the image below. This does not happen on every UITableView, just some (with no apparent pattern).

enter image description here

4条回答
仙女界的扛把子
2楼-- · 2019-04-05 08:48

This is definitely a bug in XCode6-Beta2. I found a workaround. Select the storyboard, and go to the File Inspector utility. Uncheck the option "Use Auto Layout" then click "Disable Size Classes" in the popup.

Auto Layout seems to be quite broken in beta2. Once you turn off Size Classes, the mysterious "ambiguous scrollable content" warnings will also go away.

I was able to turn Size Classes and Auto Layout back on afterward and the gray rectangle is still gone, but everything is in the wrong place after losing the Size Classes info. It's a mess.

查看更多
虎瘦雄心在
3楼-- · 2019-04-05 08:52

Strangely enough, it has to do with the Table View Separator Style. If you set that to None, the problem will go away. But of course, then you have no separators! If you want to use Single Line separators, you have to manually specify a cell height in -tableView:heightForRowAtIndexPath:.

I have no idea why this is the case, but I am guessing it has something to do with the new self-sizing table rows. Time to do some research :)

查看更多
爷的心禁止访问
4楼-- · 2019-04-05 09:01

In iOS 8, you must specify a height in the UITableView's delegate:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44.0;
}

In iOS 7 and earlier, a default was accepted. See this link for more information.

查看更多
Luminary・发光体
5楼-- · 2019-04-05 09:03

In iOS 8 the row height can be set automatically for you. All you have to do is set a top and bottom constraint to the contentView of the UITableViewCell, like this (notice the constraints):

Interface builder - defining the uitableviewcell

By doing this, the row height will be automatic and you won't need to set a fixed height. This fixes the gray background color you have encountered.

Resource: http://www.shinobicontrols.com/blog/posts/2014/07/24/ios8-day-by-day-day-5-auto-sizing-table-view-cells

查看更多
登录 后发表回答