zoukankan      html  css  js  c++  java
  • iOS开发总结(A0)- make table view more responsive

     table view 是ios中非常重要一个view,它的流畅程度非常影响app的体验。

    如果tableview cell 的内容复杂,绘制时间长,由于view的绘制是在主线程上进行的,这样会使tableview 反应卡顿,

    那么如何使table view与用户交互更流畅呢?

    以下参考wwdc视频,说明解决的方法

    (对于所有绘制复杂的view,均适用)

    1. 异步加载数据(比如从网络上获取数据)

     用非mainqueue,加载数据,用main queue 更新ui

    2. 异步绘制(不在主线程上)

    在image context 上draw,得到image,然后在mainqueue中添加到uiview中

    如下:

    UIGraphicsBeginImageContextWithOptions(size,opaque,scale);
    
    // draw code
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();

     如果view某个位置上有UIResponder,可通过addsubview 的方式增加

    3. 使用NSOperationQueue 和 Operation 多线程编程,与GCD相比, operation可以适时取消

    比如当view消失时(如viewcontroller disappear或者view removefromsuperview,或者cell didEndDisplayingCell),那么与之相关的操作应取消([operationQueue cancel])

    (特别是从网络加载数据,如果viewcontroller disappeared,应该及时取消与该vc相关的数据加载)

  • 相关阅读:
    ‘Host’ is not allowed to connect to this mysql server
    centos7安装mysql
    further configuration avilable 不见了
    Dynamic Web Module 3.0 requires Java 1.6 or newer
    hadoop启动 datanode的live node为0
    ssh远程访问失败 Centos7
    Linux 下的各种环境安装
    Centos7 安装 python2.7
    安装scala
    Centos7 安装 jdk 1.8
  • 原文地址:https://www.cnblogs.com/beddup/p/4621582.html
Copyright © 2011-2022 走看看