简体   繁体   English

UITableView上的iOS 8灰色框

[英]iOS 8 gray box over UITableView

I am making an app where I need to use UITableView s 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. 我正在创建一个应用程序,我需要使用UITableView以有组织的方式显示内容,但自从我更新到iOS 8和Xcode 6后,我几乎在整个视图中都得到了一个神秘的灰盒子。 This can be seen in the image below. 这可以在下图中看到。 This does not happen on every UITableView , just some (with no apparent pattern). 这不会发生在每个UITableView ,只有一些(没有明显的模式)。

在此输入图像描述

In iOS 8 , you must specify a height in the UITableView 's delegate: iOS 8 ,您必须UITableView的委托中指定高度:

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

In iOS 7 and earlier, a default was accepted. iOS 7及更早版本中,接受了默认值。 See this link for more information. 有关更多信息,请参阅此链接

This is definitely a bug in XCode6-Beta2. 这绝对是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. 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. 一团糟。

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: . 如果要使用单行分隔符,则必须在-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 :) 是时候做一些研究了:)

In iOS 8 the row height can be set automatically for you. 在iOS 8中,可以自动为行高设置行高。 All you have to do is set a top and bottom constraint to the contentView of the UITableViewCell, like this (notice the constraints): 您所要做的就是为UITableViewCell的contentView设置一个顶部和底部约束,如下所示(注意约束):

界面构建器 - 定义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 资源: http//www.shinobicontrols.com/blog/posts/2014/07/24/ios8-day-by-day-day-5-auto-sizing-table-view-cells

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM