In iOS 7, why UITableView's contentInset has bottom value despite the UITabBarController is hidden?

家住魔仙堡 提交于 2020-01-02 21:00:27

问题


I don't know why UITableView has bottom inset automatically despite I make UITabBarController be hidden by calling [setHidden:YES] before.

The view controller who has UITableView is a child of UITabBarController. I already know that automaticallyAdjustsScrollViewInsets helps any UIScrollView get proper 'contentInset' depending on status of it's container view controller.

So, I expected that UITableView's bottom contentInset will be 0 if UITabBar is hidden. But, doesn't do that.

Although automaticallyAdjustsScrollViewInsets is YES, should I manually adjust that value when UITabBar is hidden?


回答1:


Tab bars have never been meant to be hidden - after all why have a UITabBarController if you want to hide the tab bar. In the documentation, you are warned not to modify the tab bar object directly:

You should never attempt to manipulate the UITabBar object itself stored in this property.

This is exactly what you are doing when setting it to hidden.

In iOS6 this has worked, but now in iOS7, it doesn't. And it seems very error prone to hide it. When you finally manage to hide it, if the app goes to the background and returns, Apple's layout logic overrides your changes. There are many such triggers.

My suggestion is to change your design. Perhaps display the data modally.




回答2:


Putting this here for anyone who gets this problem for nested view controllers.

My view controller containment hierarchy is:

UINavigationController
  |--UIViewController
     |--UITabBarController
        |--UIViewController

The last view controller has a UITableView whose scrollIndicatorInsets keep getting offset by the tab bar controller's UITabBar height even if it is hidden.

Solution: Set automaticallyAdjustsScrollViewInsets to false in the view controller that contains the tab bar controller (and is inside the UINavigationController). No need to set additional properties in the tab bar controller itself and the second view controller where the UITableView is.



来源:https://stackoverflow.com/questions/20737679/in-ios-7-why-uitableviews-contentinset-has-bottom-value-despite-the-uitabbarco

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