Stop UITableView from autoscrolling in iOS 8

I have a tableview that only automatically scrolls in iOS 8 when I open a new view with[self.navigationController pushViewController:newViewController animated:YES];

Detailed problem:

Now I'll go over how I get this problem, especially on iOS 8. Take any table that has about 50 records, scroll down to make the 10th record at the top of the table. Then select any item in the table. Use the method below to push the view controller to the row selection in the table view.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    // Open the New View
    NewViewController *newVC = [[NewViewController alloc] init];
    [self.navigationController pushViewController:newVC animated:YES];
}

      

Now you will find that when returning from NewViewController

the previous ViewController, the tableview will automatically scan some distance. The table view does not stay in the scroll position, it always automatically changes its position.

+3


source to share


2 answers


I had the same problem. I was using the new iOS 8 dynamic cell. I installed:

self.tableView.estimatedRowHeight = 50.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

      

The problem was that some of the cells were much higher than 50. The solution was to provide a delegate method estimatedHeightForRowAtIndexPath

and return values ​​that are closer to the actual cell height. For example:



-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row == 1) {
        return 300.0;
    }

    return 50;
}

      

Another solution is to calculate the height of the cell using systemLayoutSizeFittingSize

internally cellForRowAtIndexPath

and cache that value. Internally estimatedHeightForRowAtIndexPath

specify the cached values, but return the default if the cell height is not already cached.

+1


source


Just uninstall self.tableView.estimatedRowHeight = xxx;

It works for me. The problem occurs in iOS8 and does not appear in iOS10



0


source







All Articles