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. W
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.
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.
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) {
super.viewDidAppear(animated)
tableView.contentOffset = offset
}
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
offset = tableView.contentOffset
}
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];
}