繁体   English   中英

将UITableView滚动到特定部分

[英]Scroll UITableView to a particular section

我希望我的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]

滚动tableview,以便所需的部分可见,但不一定在顶部或底部:

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];

在此处检查答案: 如何将UITableView滚动到不包含任何行的部分?

尝试使用这个

[self.tableView scrollToRowAtIndexPath:YOUR_INDEX_PATH_OF_SECTION atScrollPosition:UITableViewScrollPositionTop animated:YES]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM