I've set up a table view so that it will scroll to a certain row when its view controller loads. I put this code into the viewDidLoad method, and it works how I expect it:
[thisTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:16 inSection:0]
atScrollPosition:UITableViewScrollPositionTop animated:YES];
However, if I change that last bit to animated:NO
, it doesn't scroll at all. I'm fine with having it animate, but I'm wondering: why doesn't it scroll if animated is set to NO?
In viewDidLoad, your tableView is empty, scrolling to row 16 is then not possible. The call is evaluated immediately because no need for animation
When you use animated:YES, the animation is delayed until the view is displayed, your table is populated by then.
You may want to use this kind of code in viewDidAppear (or viewWillAppear) instead, when your table has already been populated with data. This will call it every single time the view is presented though (unless you add some logic), not sure if that meets your requirement...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With