Rules for the contentInset of a UITableView in iOS 7?

I'm curious as to how/when the system determines whether to default UITableView contentInsets to 64.

I've got a UITableView placed in a regular UIViewController, which itself sits in a UINavigationController with a translucent nav bar. The tableview's auto layout tells it to fill the view of the UIViewController.

Now, by default, the tableview will have a top content inset of 64.f. I can prevent that behavior by manually setting the content inset, or using edgesForExtendedLayout on the UIViewController. For now, I'm leaving it alone.

However, if I insert a subview between self.view and the tableview, the default top inset of the tableview becomes 0.0f, and I have to manually adjust it back to 64.f.

My question is this: How does the view controller determine whether to change the inset or not? Does it actually just check if self.view's top subview is a tableview/scrollview?


I'v just encountered this problem this afternoon, I added a UIButton and then a UITableView inside a normal ViewController. I set the origin of the UITableView to be (0, 64), it appeared normal just below the Navigation Bar. But after I deleted the UIButton and left the UITableView alone, it appeared to be another 64 inset below the Navigation Bar. Really weird!

And the first question searched out is yours, but no answer, really upset......But there are good answers there!

To be brief, if the main view or the first subview of the main view is a class or subclass of UIScrollView, eg UITableView, it works. Otherwise, the view controller doesn't know which UIScrollView to work.

Here is the reference: iOS 7 Table view fail to auto adjust content inset

链接地址: http://www.djcxy.com/p/90322.html

上一篇: 在ios swift中垂直滚动视图内的水平滚动视图问题

下一篇: iOS 7中UITableView的contentInset规则?