ios - 将 UITableView 滚动到特定部分

标签 ios objective-c uitableview

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

相关文章:

ios - 当点击 MKAnnotationView 时显示 UIMenuController

iphone - 如何从应用程序转到 iPhone 设置

ios - ViewController添加UITableView使用scrollViewDidScroll popViewControllerAnimated崩溃

ios - 带有 UIBlurEffect 的表格 View 变得迟钝

iOS编译错误: No visible @interface for 'setLocationManager' declares the selector

ios - 读取未知数量的传入字节

ios - 将两个坐标点转换为东西向和南北向的距离

objective-c - 如何在 Objective-C 中创建首选项窗口?

ios - 在 Sqlite3 数据库中存储自定义类对象失败

iphone - heightForRowAtIndexPath崩溃