0

I have a UIViewController that contains a TableView and an GADBannerView at the bottom. When an ad is received I change the height of the TableView so the ad doesn't cover any cells. This worked without any problem on my iPhone 6 (iOS 10) and in the simulators (iOS 10), but for some reason when testing my app on an old iPhone 4s (iOS 9), the TableView height gets reset if I leave the view controller and then return to it. Why does this happen and how can I prevent it?

This is the code I use to resize the tableview.

- (void)adViewDidReceiveAd:(GADBannerView *)view {

   if (!adRecieved) {

    view.hidden = NO;
    CGRect currentRect = self.tableView.frame;
    currentRect.size.height -= CGRectGetHeight(view.frame);
    self.tableView.frame = currentRect;

    adRecieved = YES;
}
RainKing
  • 43
  • 6
  • Do you perhaps have some code in one of the default view controller functions that is resetting the view frame on reappear? I would check your implementation of viewWillAppear, viewDidLoad etc and start from there. Drop in some breakpoints and see what the frame values are for width and height when you come back in – ascendancy05 Jul 18 '17 at 23:29
  • @ascendancy05 I've looked through my code and there's nothing I can see that would cause the tableview frame to reset. The frame size is 320x480 before the ad loads and then 320x430 afterwards, but when I re-enter the view controller it goes back to 320x480. This doesn't happen on my iPhone 6 or the simulator so I don't see how it can be code related. – RainKing Jul 19 '17 at 00:38
  • @RainKing : Is it possible display different Ads on each recurring items? – Priya Jun 22 '20 at 01:21

1 Answers1

1

I solved the problem by just editing my table view constraints instead. Now it behaves the same way on all devices.

- (void)adViewDidReceiveAd:(GADBannerView *)view {

    if (!adRecieved) {

        view.hidden = NO;

        self.tableViewBottom.constant = -50;

        adRecieved = YES;
    }
}
RainKing
  • 43
  • 6