开发者

Scrolling UITableView to valid index path throws error

Why would the following code throw this error?

if ([self.tableView.dataSource numberOfSectionsInTableView:self.tableView] > 0 && [self.tableView.dataSource tableView:self.tableView numb开发者_运维百科erOfRowsInSection:0] > 1) {
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
}

throws

*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]: section (0) beyond bounds (0).'

It's pretty early in the morning, but I'm stumped.


Try to call [self.tableView reloadData] just before the lines that you post.

I bet that the datasource is ready after the table is rendered and you call the scrollTo... method before rendering the table with the data in the datasource...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜