简体   繁体   中英

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?

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;

This did the trick here (within Interface Builder):

TabBar 上方的 TableView

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!

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.

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
}

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 ...

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

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

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.

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.

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.

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

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