zoukankan      html  css  js  c++  java
  • This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.

    一,经历

    <1> 使用SDWebImage下载 成功图片后,将图片设置给 self.imageView.image,提示如题所示的错误提示.

    <2>第一反应就是慢慢注释掉代码进行调试,结果发现是在成功的回调中出事了,代码如下:

     1 - (void)setupDownloadImage{
     2     NSURL *url = [NSURL URLWithString:@"http://i4.pdim.gs/dmfd/200_200_100/t01f117f76fc58c257c.gif"];
     3 
     4     SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
     5    [downloader downloadImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
     6         if (data != nil && image != nil) {
     7             UIImage *image = [UIImage sd_animatedGIFWithData:data];
     8                 self.imageView.image = image;
     9         }else {
    10             UIImage *image = [UIImage imageNamed:@"12345"];
    11             self.imageView.image = image;
    12         }
    13     }];
    14 }

    <3>初步怀疑是sdwebimage 设置gift 图片失败,就在成功的回调中使用了一张本地的图片,依旧报错.

    <4>仔细研究了提示,发现了关键词"a background thread",才知道是 sdwebimage 的后台线程在执行一些操作,仔细想了想才知道是更新 UI的操作必须在主线程中执行.

    二,总结

    <1>一定要注意子线程中对更新 UI 的使用.

  • 相关阅读:
    使用Enablebuffering多次读取Asp Net Core 请求体
    Windows Forms和WPF在Net Core 3.0框架下并不会支持跨平台
    .Net Core IIS下无Log4Net日志输出,命令行下却有(dotnet运行)
    ElasticSearch7.x Bool查询Java API
    ElasticSearch7.X Java client
    Spark RDD转DataFrame
    spark写mysql
    spark读取mysql
    Spark2.x写Hbase1-2.x
    Spark2.x读Hbase1-2.x
  • 原文地址:https://www.cnblogs.com/lz465350/p/5196478.html
Copyright © 2011-2022 走看看