F.SO4
F.SO4

Reputation: 167

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!

Upvotes: 2

Views: 5804

Answers (7)

Wimukthi Rajapaksha
Wimukthi Rajapaksha

Reputation: 1019

If you changed self.hidesBottomBarWhenPushed=true in previous view controller, then make sure to change it to self.hidesBottomBarWhenPushed=false inside override func prepare(for segue: UIStoryboardSegue, sender: Any?) {}

Upvotes: 0

Tyten
Tyten

Reputation: 333

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:

Adjust scroll view insets

Under opaque bars

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

Upvotes: 2

Alan
Alan

Reputation: 123

You should config the corresponding view controller with following code to remove the edges extend (It defaults to UIRectEdgeAll)

edgesForExtendedLayout = []

Upvotes: 1

mkkrolik
mkkrolik

Reputation: 1259

Try this

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

Upvotes: 0

Karl-John Chow
Karl-John Chow

Reputation: 805

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);
}

Upvotes: 2

Vishal Sonawane
Vishal Sonawane

Reputation: 2693

Try to use constraints for tableView and TabBar like:

enter image description here

Upvotes: -1

TheHungryCub
TheHungryCub

Reputation: 1960

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.

Upvotes: 6

Related Questions