[英]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 numberOfRowsInSection: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).' ***由于未捕获的异常“ NSRangeException”而终止应用程序,原因:“-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]:超出范围(0)的第(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. 尝试在您发布的行之前调用
[self.tableView reloadData]
。
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... 我敢打赌,在呈现表之后,数据源已准备就绪,您可以在使用数据源中的数据呈现表之前调用
scrollTo...
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.