[英]Scroll UITableView to a particular section
I want my UITableView
to scroll to a particular section, how do i achieve this. 我希望我的
UITableView
滚动到特定部分,我如何实现这一点。 I have tried a lot of suggestions on SO, and for some strange reason nothing seems to work. 我已经尝试了很多关于SO的建议,并且出于某些奇怪的原因,似乎没有任何效果。 Any help is appreciated.
任何帮助表示赞赏。 Thank you.
谢谢。
Try by using below lines of code: 请尝试使用以下代码行:
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];
});
Edit: 编辑:
use the following NSIndexPath
to scroll to a section containing 0 rows: 使用以下
NSIndexPath
滚动到包含0行的部分:
[NSIndexPath indexPathForRow:NSNotFound inSection:section]
scroll the tableview so the desired section is visible but not necessarily at the top or bottom: 滚动tableview,以便所需的部分可见,但不一定在顶部或底部:
CGRect sectionRect = [tableView rectForSection:indexOfSectionToScrollTo];
[tableView scrollRectToVisible:sectionRect animated:YES];
to scroll so the section is at the top do this: 滚动以使该部分位于顶部,请执行以下操作:
CGRect sectionRect = [tableView rectForSection:indexOfSectionToScrollTo];
sectionRect.size.height = tableView.frame.size.height;
[tableView scrollRectToVisible:sectionRect animated:YES];
Check answer here: How do I scroll a UITableView to a section that contains no rows? 在此处检查答案: 如何将UITableView滚动到不包含任何行的部分?
尝试使用这个
[self.tableView scrollToRowAtIndexPath:YOUR_INDEX_PATH_OF_SECTION atScrollPosition:UITableViewScrollPositionTop animated:YES]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.