来自UITableView的错误值:iOS8中的rowHeight [英] Wrong value from UITableView:rowHeight at iOS8
问题描述
我用来创建矩形的代码(至少在iOS7之前)是
The code I used to create a rectangle (at least until iOS7) was
CGRect rect = [cTableView frame];
rect.origin.y += [cTableView rowHeight];
searchOverlayView = [[BecomeFirstResponderControl alloc] initWithFrame:rect];
在iOS7上, cTableView
(一个实例a UITableView
)返回 44
。使用iPhone 5s在iOS8中测试返回 -1
。
On iOS7, cTableView
(an instance of a UITableView
) returned 44
. Testing in iOS8 with an iPhone 5s returns -1
.
为什么会这样?为了使我的应用程序向后兼容iOS7,需要使用哪些正确的代码?
Why is this happening? What is the correct code that needs to be used in order for my app to be backwards compatible with iOS7?
推荐答案
Apple将iOS8中的默认行高改为 UITableViewAutomaticDimension
,其中声明为 -1
。这意味着您的表视图已设置为自动单元格高度计算。
Apple changed the default row height in iOS8 to UITableViewAutomaticDimension
, which is declared as -1
. This means that your table view is set up for automatic cell height calculation.
您需要实现autoLayout(推荐)或实现新的委托方法: heightForRowAtIndexPath
。以下是关于自动布局的一个很好的问题:在UITableView中使用自动布局进行动态单元布局&可变行高
You will either need to implement autoLayout (recommended) or implement the new delegate method: heightForRowAtIndexPath
. Here's a great question about auto layout: Using Auto Layout in UITableView for dynamic cell layouts & variable row heights
无论如何,似乎你实际上是硬编码44(旧的默认值),所以你可以这样做(不推荐)。
Seems like you were effectively hard coding 44 (the old default) anyway, though, so you could just do that (not recommended).
这篇关于来自UITableView的错误值:iOS8中的rowHeight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!