I have a view containing a UITableView. Above the table I’d like to display an iAd. I figured the best way to do this was to set the contentInset for the table to the height of the iAd banner – all good so far.
The app supports rotation, so I have this code:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
NSString *bannerSize = (UIInterfaceOrientationIsPortrait(interfaceOrientation)) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifierLandscape;
int bannerHeight = [ADBannerView sizeFromBannerContentSizeIdentifier:bannerSize].height+1;
iAdBanner.currentContentSizeIdentifier = bannerSize;
[mainTable setContentInset:UIEdgeInsetsMake(bannerHeight, 0, 0, 0)];
}
This works on the first rotate, but when I rotate back, the contentInset doesn’t appear to have been changed, in fact every time I rotate the device it appears to be set to the ‘inverse’ value
But it is working – in that if I attempt the scroll the table, everything jumps into place.
After much reading, I added the following line to the end of the code above:
[mainTable scrollRectToVisible:CGRectMake(0, 0, 10, 10) animated:NO];
This worked! – BUT – I don’t want the table to scroll back to the top every time the device is rotated, so I tried this:
[mainTable scrollRectToVisible:CGRectMake(mainTable.contentOffset.y+bannerHeight, 0, 10, 10) animated:NO];
But if I’m not at the top of the table the original problem reappears, in that the header of the current section (it’s a plain table) is about 20 pixels too high or too low, fixed immediately by manually scrolling.
So now I’m lost – any ideas?
you probably would want to use a UIViewController instead of a UITableViewcontroller and addd the UITableView programmatically. Then, you can easily set the frames of the ad and the tableview. And when rotated, use the rotating methods to change the frames again!