为什么以下代码会抛出此错误?
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];
}
引发
***由于未捕获的异常'NSRangeException'终止应用程序,原因:' - [UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]:section(0)超出bounds(0)。'
早上很早,但我很难过。
答案 0 :(得分:2)
尝试在发布的行之前调用[self.tableView reloadData]
。
我敢打赌,在呈现表之后数据源已准备好,并且在使用数据源中的数据呈现表之前调用scrollTo...
方法...