How to stop UITableView from returning to top cell after popover

I have a tableView full of images. When a user taps on an image (within the cell), a viewController with a larger zoomable version of the image is called with a popover segue. When i dismiss the popover and return to my tableView, it automatically displays the top cell of the table. Is there any way to stop this happening, and return to the previous position/cell before the popover was called?

To call the popover i use

  • How to hide Toolbar in IQKeyboardManager iOS Swift 3
  • on iOS/iPhone: “Too many open files”: need to list open files (like lsof)
  • Why AVSampleBufferDisplayLayer stops showing CMSampleBuffers taken from AVCaptureVideoDataOutput's delegate?
  • AVCaptureTorchModeAuto does not continuously update torch mode
  • Set dimensions for UIImagePickerController “move and scale” cropbox
  • Xcode 8 Swift 3: Modal presentation transitioning delegate not called
  • performSegueWithIdentifier("segueToPopOver", sender: tap.view)

    to dismiss it i use the following:

     let tmpController :UIViewController! = self.presentingViewController;
     self.dismissViewControllerAnimated(true, completion: {()->Void in
            tmpController.dismissViewControllerAnimated(true, completion: nil);

    4 Solutions Collect From Internet About “How to stop UITableView from returning to top cell after popover”

    Get tableview content offset before displaying your zoomViewController.

    -(void)viewWillDisappear:(BOOL)animated {
      [super viewWillDisappear:animated];
      tableViewContentOffset = self.tableView.contentOffset;

    and set tableview offset again in viewWillAppear

    -(void)viewWillAppear:(BOOL)animated {
       [super viewWillAppear:animated];
       [self.tableView setContentOffset:tableViewContentOffset];

    please check, if you are calling reloadData in viewWillAppear or viewDidAppear.
    or if you are calling any reloadsection in either of these 2 methods.

    You can also validate these calls also in viewWillDisappear/viewDidDisappear methods too.

    most probably the reason for this behavior is that you are calling table reload some where between opening and closing the popover view (probably inside one or more of these methods like viewDidAppear, viewWillAppear etc). If you can simply remove it then it wont be scrolling to top.

    or you can keep the content offset just before opening popover view then set the offset after closing it,

    override func viewDidAppear(animated: Bool) {
        tableView.contentOffset = offset
    override func viewDidDisappear(animated: Bool) {
        offset = tableView.contentOffset

    Cache selected indexPath of the selected image cell, and in viewWillAppear method,

        if(selectedPath != nil) {
            [self.tableView scrollToRowAtIndexPath:selectedPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

    This will scroll back to your selected image row.