I've created an extremely simple demo app to test the functionality of automaticallyAdjustsScrollViewInsets
, but the last cell of the tableView is covered by my tab bar.
My AppDelegate code:
UITabBarController *tabControl = [[UITabBarController alloc] init]; tabControl.tabBar.translucent = YES; testViewController *test = [[testViewController alloc] init]; [tabControl setViewControllers:@[test]]; [self.window setRootViewController:tabControl];
My testViewController (subclass of UITableViewController) Code:
- (void)viewDidLoad { [super viewDidLoad]; self.automaticallyAdjustsScrollViewInsets = YES; self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds]; self.tableView.dataSource = self; self.tableView.scrollIndicatorInsets = self.tableView.contentInset; //[self.view addSubview:self.tableView]; // Do any additional setup after loading the view. } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 20; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""]; cell.textLabel.text = @"test"; return cell; }
Is this a bug in iOS 7? If not, what did I do wrong?
I think that automaticallyAdjustsScrollViewInsets
only works when your controllers view
is a UIScrollView
(a table view is one).
You're problem seems to be that your controller's view
is a regular UIView
and your UITableView
is just a subview, so you'll have to either:
Make the table view the "root" view.
Adjust insets manually:
UIEdgeInsets insets = UIEdgeInsetsMake(controller.topLayoutGuide.length, 0.0, controller.bottomLayoutGuide.length, 0.0); scrollView.contentInset = insets;
Edit:
Seems like the SDK is capable of adjusting some scroll views despite not being the controller's root view.
So far It works with UIScrollView
's and UIWebView
's scrollView
when they are the subview at index 0
.
Anyway this may change in future iOS releases, so you're safer adjusting insets yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With