Accatyyc
Accatyyc

Reputation: 5828

Tab bar covers UITableView's last cell

I'm developing an application based on the Tab Bar application preset. In one of the tabs I have a table view showing a lot of data, but half the last cell in the table view is covered by the tab bar when I've scrolled to the bottom.

Anyone has a solution to this?

Upvotes: 11

Views: 11177

Answers (12)

Kasra Babaei
Kasra Babaei

Reputation: 307

Swift 3:

This is what worked perfectly for me. This code not only stop the last cell showing behind the tab bar, but also pushes up the scroll indicator. Put the code in your viewDidLoad():

if let bottomInset = navigationController?.tabBarController?.tabBar.frame.size.height {
    tableView.contentInset.bottom = bottomInset
    tableView.scrollIndicatorInsets.bottom = bottomInset
}

or you could do this:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    tableView.contentInset.bottom = view.safeAreaInsets.bottom
    tableView.scrollIndicatorInsets.bottom = view.safeAreaInsets.bottom
}

Upvotes: 2

A.J. Hernandez
A.J. Hernandez

Reputation: 968

SWIFT

I had been having this problem where when I embed a UITableViewController into a UITabBarController, the last cell (or the bottom or a large cell) would remain under the TabBar when fully scrolled down. After a day of trying various codes and work arounds which didn't work, I simply re-embeded my UITableViewController into a Navigation Controller which was them embedded into a TabBar Controller. The spacing is fixed and the table view clears the tabBar now.

Upvotes: 0

LKM
LKM

Reputation: 2450

I just solved this problem by adding constant number... hard coding... How about finding threshold value fit to you?

Upvotes: 1

Pawel Jurczyk
Pawel Jurczyk

Reputation: 165

For me it was just that the table view in UIViewController didn't have any constraints, once I pinned in to the edges of the view it fixed itself.

Upvotes: 0

backslash-f
backslash-f

Reputation: 8193

This did the trick here (within Interface Builder):

TableView above TabBar

Upvotes: 11

Chris
Chris

Reputation: 1034

There are a couple of solutions for this.

1.) Assuming that you are using translucent tool bars, you have to make the tool bars opaque.

2.) If you are using StoryBoard and you are putting a TableView inside your ViewController, assuming it's a ViewController and not a TableViewController.

3.) You can manually add padding/spacing.

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.extendedLayoutIncludesOpaqueBars = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
}

or

UIEdgeInsets insets = UIEdgeInsetsMake (0,sizeOfTableView - sizeOfTabBar, 0, 0);
self.tableView.contentInset = inset;
self.tableView.scrollIndicatorInsets = inset;

Hope this helps & Happy coding!

Upvotes: 4

Quang Huỳnh
Quang Huỳnh

Reputation: 1

I think you have a custom Tabbar, you need reset the height of Tabbar equal to the height of the background image of this Tabbar.

UITabBar * tabbar = self.tabBar ; 
[tabbar setBackgroundImage:[UIImage imageNamed:@"image.png"]] ; 
[tabbar setFrame:CGRectMake(0, 480 - imageHeight, 320, imageHeight)];

Upvotes: -2

Gon
Gon

Reputation: 1143

Select the view where you have your tableview, open attribute inspector, in Simulated Metrics section, select Tab Bar for Bottom Bar item.

Then XCode would update your view, reserving space for TabBar. So your tableview would not be covered.

Upvotes: 0

JavierGiovannini
JavierGiovannini

Reputation: 919

Adding a footer space worked for me:

//this prevent the tabbar to cover the tableview space
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 90)];
footer.backgroundColor = [UIColor clearColor];
myTableView.tableFooterView = footer;

Upvotes: 17

Mazyod
Mazyod

Reputation: 22559

REAL ANSWER:

I had this problem, and ended up here ... So even if this is old, here is how I solved this issue:

I had a UITabBar controller with one tab being a UIViewController, and it had a single added line:

[self.view addSubview:navController.view];

This is wrong .. Even if the code worked, the concept is wrong (at least in my case), the navController should be directly linked in the UITabBar as one of the tabs...

So, what's the real answer?

You must have implemented the navigation controller incorrectly. As proof is that I had this issue, as I explained, and also This Guy...

Upvotes: 2

Accatyyc
Accatyyc

Reputation: 5828

I've found the only solution to this is to add a padded footer for the tableview:

http://www.iphonedevsdk.com/forum/iphone-sdk-development/18180-resizing-uitableview-programatically.html

Upvotes: 1

jer
jer

Reputation: 20236

Look at the size of the tab bar, and adjust the size of your table view accordingly. Read the docs on the frame property, IB lets you set the size of things if you're using IB for this purpose, etc.

Upvotes: 3

Related Questions