Search code examples
iosobjective-cscrollviewtableviewpush

ScrollView contentOffset reset after pushViewController


I'm experiencing a problem with ScrollView, my scrollView has 640 of width, from 0 to 320 it's a mapView, from 320 to 640 it's a tableView. I have a segmentedButton with 2 options to switch my view from contentOffset from 0 to 320 in x. The problem is, if I switch to contentOffset of 320 in x and press a cell of tableView, after releasing the button to push other viewController, the contentOffset of my scrollView is reseting to 0 in x. I need to keep contentOffset on the tableView, at 320 in x. I tried many things, like playing around with viewWillDisappear and the lifecycle methods. The closest I've been able to reach was making it going back to the tableView after pressing back. Although, I couldn't make it stay on the tableView to push the next viewController.

Any help is appreciated!

(Ps: I've search for similar questions, but the only one that could help, I couldn't understand very well, the others have similar but different problems).

Thanks


Solution

  • I had the same problem. Here is the solution: 1. I'm doing content offset backup in viewWillDisappear 2. Restoring offset without animation in viewWillAppear.

    UPDATE: Be sure you are not adjusting contentSize in viewWillLayoutSubviews or in methods mentioned above.