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

     
  • 相关阅读:
    解决asp.net mvc的跨域请求问题
    centos安装nodejs
    webapi中配置返回的时间数据格式
    centos安装django
    在Linux CentOS 6.6上安装Python 2.7.9
    nginx日志切割脚本
    apache单ip配置多端口多站点
    centos开启rewrite功能
    Fast Matrix Operations
    1400
  • 原文地址:https://www.cnblogs.com/LynnAIQ/p/5915117.html
Copyright © 2011-2022 走看看