Bcf Ant Bcf Ant - 1 year ago 82
iOS Question

TableView starts in the wrong position initially

This issue has come about as I update an app from iOS 7 to iOS 8. My tableview starts in the wrong position initially. Once you touch it or scroll it. The tableview scrolls into the correct position and works as intended.

The table view is embedded within a UIPageViewController.

UITableView *tableView = (id) [self.view viewWithTag:5];
[tableView registerClass:[BroadcastCell class] forCellReuseIdentifier:CellBroadcastTableIdentifier];
[tableView registerClass:[BroadcastHeaderCell class] forCellReuseIdentifier:CellBroadcastHeaderTableIdentifier];
[tableView setSeparatorInset:UIEdgeInsetsZero];
tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 64.0f)];
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 0.0f)];
[tableView setDelegate:self];
[tableView setDataSource:self];
tableView.backgroundColor = [UIColor clearColor];
tableView.opaque = NO;
tableView.backgroundView = nil;
tableView.rowHeight = UITableViewAutomaticDimension;
tableView.estimatedRowHeight = UITableViewAutomaticDimension;

Screenshot can be found - https://pbs.twimg.com/media/Byh_5eIIQAA06ok.png:large

Answer Source

I had the same issue. After much effort I found out that in the previous view I was using

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"title-bar-bg.png"] forBarMetrics:UIBarMetricsDefault];

I changed it to

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title-bar-bg.png"] forBarMetrics:UIBarMetricsDefault];

and the problem was solved.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download