iOS 7 Custom TableView Is Under TabBar
Asked Answered
H

16

32

Im trying port my app to iOS7, but my custom TableViewController is showing the last row (cell) under the TabBar :(

Im searching a lot for it, but i dont find any solution. Can anyone help me?

My Custom Table View class

The error is shown in the blow screenshot (only is showing a part of last product because im draging to up to show the hidden product under the tabbar):

screenshot

Thanks.

Hooge answered 4/10, 2013 at 5:5 Comment(0)
I
31

I found the answer to your question on another post, answered by dariaa, here:

Tab Bar covers TableView cells in iOS7

It worked great for me.

Please no credit for me, because I'm not the original guy who solved it.

In your custom TableViewController, add these two lines under [super viewDidLoad]:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.tableView.contentInset = UIEdgeInsetsMake(0., 0., CGRectGetHeight(self.tabBarController.tabBar.frame), 0); 
} 
Interpellation answered 24/10, 2013 at 22:16 Comment(1)
Thanks, this fixed the issue with my tab bar.Transversal
G
35

I've got the same problem and solved it using storyboard. At Tab Bar Controller, go to attribute inspector, Simulated Metrics, and set the Bottom Bar to Opaque Tab Bar. That's it! See image bellow for description. enter image description here

Saudações! (Greetings!)

Geber answered 8/10, 2013 at 12:32 Comment(3)
Opaque is just a workaround : Don't use it, it's ugly.Copyboy
After I have changed to Opaque Tab Bar, I change back to None then it still work.Municipal
You are a hero sir!Rugger
I
31

I found the answer to your question on another post, answered by dariaa, here:

Tab Bar covers TableView cells in iOS7

It worked great for me.

Please no credit for me, because I'm not the original guy who solved it.

In your custom TableViewController, add these two lines under [super viewDidLoad]:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.tableView.contentInset = UIEdgeInsetsMake(0., 0., CGRectGetHeight(self.tabBarController.tabBar.frame), 0); 
} 
Interpellation answered 24/10, 2013 at 22:16 Comment(1)
Thanks, this fixed the issue with my tab bar.Transversal
D
10

My friends, I cannot tell you how badly I struggled from this. Not a single re-configuration of Story Board never helped me. The issue was exactly like in Original Post, I've managed to fix it using:

for swift 3

self.edgesForExtendedLayout = []

for objective-c

self.edgesForExtendedLayout = NO;
Dolhenty answered 12/2, 2017 at 18:44 Comment(1)
Unbelievable, but this was the answer for my problem with a view under the tabbar.Sheik
C
8

2 lines in viewDidLoad and that's it !

self.edgesForExtendedLayout = UIRectEdgeAll;
self.tableview.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(self.tabBarController.tabBar.frame), 0.0f);
Copyboy answered 28/10, 2014 at 23:44 Comment(1)
UIRectEdgeAll is set by defaultDamato
T
6

In iOS 7 viewController uses full height. There is a property introduced as

self.automaticallyAdjustsScrollViewInsets = NO;

set it to no. then check, or set UIEdgeInset if is not set right after it.

UIEdgeInsetsMake(top, left, bottom, right)

See here https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

Edit: try also this

self.edgesForExtendedLayout = UIRectEdgeNone;
Talkfest answered 4/10, 2013 at 5:24 Comment(1)
I put it (already tested if you see commented code). But nothing solved it :(Hooge
S
5

The root cause of this problem is that automaticallyAdjustsScrollViewInsets is effective only on the First scroll view in your VC's view Hierarchy. It is not documented by Apple, but it is the only way the VC will detect the scroll view needing to be modified unless you're using a UITableViewController.

So in order to fix your issue without manually adjusting the insets, do this:

  1. Make sure "Adjust Scroll View Insets" is checked.
  2. Make sure that the tableView is the first subview in the view Hierarchy. (Move it upwards above all other elements)
Showiness answered 8/9, 2015 at 11:31 Comment(1)
Wow this made it possible to keep the translucent behaviour of the tabbar and still make the scrollview items to scroll above it. Thanks!Reach
S
2

UIViewController has two new properties to assist you : topLayoutGuide and bottomLayoutGuide. They return the height of the parent view controller's controls you need to avoid. In this case, bottomLayoutGuide will return the offset of the tab bar.

Your custom view controller is probably overriding a method and not invoking super's implementation where this would be done for you. I am guessing you are installing AutoLayout constraints or setting a view's frame manually to fill the view. You just need to include the value from [bottomLayoutGuide length] to your layout calculation. If you support rotation, you should update that value in willAnimateRotationToInterfaceOrientation:duration:.

Symbolism answered 8/10, 2013 at 15:28 Comment(0)
L
1

UINavigationController and UITabBarController both have a transparency flag that can be set programmatically or in the storyboard.

The UINavigationController also has two flags that control if the content extends under the top or bottom bar. Again you can set them programmatically or in the storyboard. This will apply to all subviews.

Each UIViewController can set its own preference in code. The property is called edgesForExtendedLayout and you can set up all combinations.

Using those properties will allow AutoLayout and Springs'n'Struts to adjust the views the way you want them regardless of the device.

There are a lot more new properties in UIViewController that you will want to have a look at.

Lussi answered 5/10, 2013 at 5:58 Comment(0)
H
1

Try the following:

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])

 self.edgesForExtendedLayout = UIRectEdgeBottom;
Homerus answered 14/10, 2015 at 5:8 Comment(0)
T
1

I've got the same problem. One solution to it is to make the ToolBar not Translucent. Here's how to do it:

  • First select the tool bar from the document viewer like here
  • Then uncheck Translucent like here

Hope this helps.

Thanks.

Totality answered 9/9, 2016 at 21:57 Comment(0)
H
0

The problem was masked using:

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 112, 0);
}

But it doesn't solve, because on each iPhone and on each app tableview i have a different space on bottom.

So this is a poor solution.

I dont know a way to solve it.

Hooge answered 5/10, 2013 at 4:50 Comment(0)
H
0

I solved my problem now, changing my BaseTableViewController to inherit from UIViewController to UITableViewController.

But using a TableView inside a UIViewController is not solved :(

Thanks.

Hooge answered 5/10, 2013 at 13:24 Comment(0)
I
0

maybe is not a right answer, also for that reason I post this answer so you can tell me if this answer could be a possible solution.

In my case, I like the translucent effect, so I have added a footer in the table and I have modified the scrollIndicators.

- (void)viewDidLoad
{
    // Do any additional setup after loading the view.
    [super viewDidLoad];
    UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.agendaItemsTable.frame.size.width, self.tabBarController.tabBar.frame.size.height)];
    self.agendaItemsTable.tableFooterView = footer;
    self.agendaItemsTable.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, self.tabBarController.tabBar.frame.size.height, 0);

}

What do you think?

Investment answered 18/10, 2013 at 15:14 Comment(0)
S
0

I had the same problem, and the up-voted answers did not solve it. See my answer to a similar question, Tab Bar covers TableView cells in iOS7.

I solved the issue by manually setting the table view's frame in the table view controller's viewWillAppear: method to the height of the screen - (status bar height + nav bar height + tab bar height).

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    // Adjust height of tableview (does not resize correctly in iOS 7)
    CGRect tableViewFrame = self.tableView.frame;
    tableViewFrame.size.height = [self heightForTableView];
    self.tableView.frame = tableViewFrame;
}

- (CGFloat)heightForTableView
{
    return CGRectGetHeight([[UIScreen mainScreen] bounds]) -
           (CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]) +
            CGRectGetHeight(self.navigationController.navigationBar.frame) +
            CGRectGetHeight(self.tabBarController.tabBar.frame));
}

If anyone finds a better solution to this problem, please share!

Sacchariferous answered 19/2, 2014 at 2:50 Comment(4)
You're using viewWillAppear incorrectly for starters here. It's a common mistake. This should go in viewWillLoad. viewWillAppear fires every time the view appears! You don't want view setup code in that method firing every time your view appears. Only dynamic code that changes should go in viewWillAppear, such as data that's getting updated on the fly. You can call view logic if it's relevant to data updating, such as a view refresh. But view setup should never go in viewWillAppear.Shedd
cocoanut: In my experience, the frames of some views haven't always been set in viewDidLoad, but they are set in viewWillAppear, so computing geometries in viewDidLoad results in incorrect values if they need to be based on views in the nib.Lepanto
@Lepanto Agreed. I put this code in viewWillAppear: because there's no guarantee the frames will be set in viewDidLoad.Sacchariferous
@cocoanut This answer explains why you shouldn't put this code in viewDidLoad.Sacchariferous
W
0

For those like xarly who want the translucent effect, and for an Autolayout solution (without setting frames), see my answer here https://mcmap.net/q/453938/-ios-7-tabbar-translucent-issue

Weaponless answered 17/10, 2014 at 7:52 Comment(0)
P
0

I had a similar problem with collection view. Changing the collection view frame and content inset below fixed it for me...

    guard let cv = collectionView,
        let tabBar = tabBarController?.tabBar else { return }

    // Resize collection view for tab bar
    let adjustedFrame = CGRect(origin: cv.frame.origin,
                               size: CGSize(width: cv.frame.width, height: cv.frame.height - tabBar.frame.height))
    cv.frame = adjustedFrame

    // Adjust content inset for tab bar
    let adjustedContentInsets = UIEdgeInsetsMake(0, 0, tabBar.frame.height, 0)
    cv.contentInset = adjustedContentInsets
    cv.scrollIndicatorInsets = adjustedContentInsets

Good luck!

Pedestrianism answered 29/4, 2018 at 3:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.