简体   繁体   中英

UITableView is under the TabBar

I have a custom UITableView with custom cells (70px height for each cell).

I have also a 49px UITabBar , but it's hides the tableView.

I've tried to add this line to the TableView awakeFromNib method but it didn't work:

self.commentsTableView.contentInset = UIEdgeInsetsMake(0, 0, 49, 0)

Any idea how can I solve this?

Thanks!

i don't know what you did exactly, but try like this:

self.edgesForExtendedLayout = UIRectEdgeAll;
self.tableview.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(self.tabBarController.tabBar.frame), 0.0f);

I hope, this will work.

I ran into this issue when dealing with a table view in a navigation controller that did not have translucent bars. I performed a setup similar to the following:

override func viewDidLoad() {
    super.viewDidLoad()

    // Without this there is some extra fast inertia when slowly
    // scrolling to the top.
    extendedLayoutIncludesOpaqueBars = true

    // Don't extend the tableview past the bottom bar, though.
    // If we do then a tab bar or bottom nav bar will block
    // content.
    edgesForExtendedLayout = [.top, .left, .right]
}

However, I later discovered that a couple of checkboxes were unchecked in a storyboard higher up the hierarchy. Specifically these two:

调整滚动视图插图

在不透明条下

Checking these two boxes removed the need to care about the content insets and the layout extending behavior in that view controller

This did the trick for me in Swift 3.

if let tabBarController = tabBarController {
    self.tableView.contentInset = UIEdgeInsetsMake(0.0, 0.0, tabBarController.tabBar.frame.height, 0.0);
}

您应该使用以下代码配置相应的视图控制器以删除边缘扩展(默认为 UIRectEdgeAll)

edgesForExtendedLayout = []

Try this

self.commentsTableView.contentInset = UIEdgeInsetsMake(49, 0, 0, 0)
self.commentsTableView.setContentOffset(CGPoint.init(x: 0, y: -49), animated: false)

如果您在之前的视图控制器中更改了self.hidesBottomBarWhenPushed=true ,那么请确保在override func prepare(for segue: UIStoryboardSegue, sender: Any?) {} self.hidesBottomBarWhenPushed=false其更改为self.hidesBottomBarWhenPushed=false

Try to use constraints for tableView and TabBar like:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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