zoukankan      html  css  js  c++  java
  • IOS学习之UITableView滚动到指定位置

    IOS学习之UITableView滚动到指定位置

    方法很简单:

    - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated

    有些需要注意的地方:

    如果在reloadData后需要立即获取tableview的cell、高度,或者需要滚动tableview,那么,直接在reloadData后执行代码是有可能出问题的。

    reloadDate并不会等待tableview更新结束后才返回,而是立即返回,然后去计算表高度,获取cell等。

    如果表中的数据非常大,在一个run loop周期没执行完,这时,需要tableview视图数据的操作就会出问题了。

    apple并没有直接提供reloadData的api,想要程序延迟到reloadData结束在操作,可以用以下方法:

    方法一:

    [self.tableView reloadData];
    [self.tableView layoutIfNeeded];
    //刷新完成

    方法二:

    [self.tableView reloadData];
    dispatch_async(dispatch_get_main_queue(), ^{
        //刷新完成
    });

    reloadDate会在主队列执行,而dispatch_get_main_queue会等待机会,直到主队列空闲才执行。

    类似函数:

    - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;

    - (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;

    - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;  // animate at constant velocity to new offset

    - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;

    当使用[tableView reloadData];刷新数据时,不能直接在后面使用上面的函数。reload

     
  • 相关阅读:
    wmware虚拟系统光盘的问题
    ORM框架SQLAlchemy
    python关于二分查找
    Python的各种推导式合集
    远程连接腾讯云服务器MySQL数据库
    Django配置404页面
    使用Python将Excel中的数据导入到MySQL
    MySQLl导入导出SQL文件
    数据结构(十三)排序
    数据结构(十二)散列表
  • 原文地址:https://www.cnblogs.com/LynnAIQ/p/5915117.html
Copyright © 2011-2022 走看看