我希望我的 UITableView
滚动到特定部分,我该如何实现。我已经尝试了很多关于 SO 的建议,但出于某种奇怪的原因,似乎没有任何效果。任何帮助表示赞赏。谢谢。
最佳答案
尝试使用以下代码行:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSInteger Section=3;//Change as required
NSInteger Row=0;//Change as required
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:Row inSection:Section];
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
});
编辑:
使用以下 NSIndexPath
滚动到包含 0 行的部分:
[NSIndexPath indexPathForRow:NSNotFound inSection:section]
滚动表格 View ,使所需的部分可见,但不一定在顶部或底部:
CGRect sectionRect = [tableView rectForSection:indexOfSectionToScrollTo];
[tableView scrollRectToVisible:sectionRect animated:YES];
要滚动使该部分位于顶部,请执行以下操作:
CGRect sectionRect = [tableView rectForSection:indexOfSectionToScrollTo];
sectionRect.size.height = tableView.frame.size.height;
[tableView scrollRectToVisible:sectionRect animated:YES];
在这里查看答案:How do I scroll a UITableView to a section that contains no rows?
关于ios - 将 UITableView 滚动到特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38435302/