I am trying to scroll my tableview to the 2nd cell:
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]
atScrollPosition:UITableViewScrollPositionNone
animated:NO];
I get the error:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]: section (1) beyond bounds (0).
'
My tableview has 30 cells that are appearing with no sections.
When I got the same error message with a one-section table, I fixed it by creating a NSIndexPath with both a row and section:
NSIndexPath *ip = [NSIndexPath indexPathForRow:itemCurrentlyPlaying inSection:0];
It's not easy to find, but the relevant convenience constructor is documented here:
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/NSIndexPath_UIKitAdditions/Reference/Reference.html
If you have no sections, then you can try the indexPathWithIndex:
class constructor:
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndex:1]
atScrollPosition:UITableViewScrollPositionNone
animated:NO];
Like pollyp, I was able to use indexPathForRow:inSection:
. I'm calling that from my viewWillAppear:
.
It looks like your error message is saying that there isn't even one section. Are you perhaps calling scrollToRowAtIndexPath:atScrollPosition:animated:
before the table data is loaded (e.g. in viewDidLoad
)? Try calling it later, in viewWillAppear:
.
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