【问题标题】:AFNetworking + Many imageviews = Crash -> Received memory warningAFNetworking + 许多图像视图 = 崩溃 -> 收到内存警告
【发布时间】:2015-05-28 18:08:33
【问题描述】:

我在使用 AFNetworking 的应用程序中从来没有遇到过问题,因为我想要显示 20 个图像视图,但现在我的应用程序崩溃了,因为我想将 imagewithURL 设置为 150 个图像视图,如果我评论该行一切正常,这是我的代码:

for (int i=0; i< Array.count; i++) {
  UIImageView *imgProd=[[UIImageView alloc] initWithFrame:CGRectMake(margenX, margenY, 220, 330)];
  imgProd.contentMode = UIViewContentModeScaleAspectFill;
  imgProd.clipsToBounds = YES;
  [imgProd setTag:i];
  // dispatch_async(dispatch_get_main_queue(), ^{
  [imgProd setImageWithURL:[NSURL URLWithString: [Array objectAtIndex:i]]];
  // });
  imgProd.userInteractionEnabled = YES;
  UITapGestureRecognizer *tap ... etc etc.
}

我放了一个dispatch_async,但是同样的问题,请大家指教!,谢谢:)

【问题讨论】:

    标签: objective-c uiimageview afnetworking didreceivememorywarning


    【解决方案1】:

    您正在创建 150 个 UIImageView 并用图像数据填充它们,这会弄乱您的内存并使您的应用程序崩溃。

    你应该创建一个 UITableView 或 UICollectionView 并使用内置的内存处理程序

    dequeueReusableCellWithReuseIdentifier

    ,在屏幕上显示图像并在单元格中仅重用一个相同的 UIImageView。不创建 150 个 uiimageview,即只需要一个。

    一些快速的谷歌搜索让我了解了本教程: https://www.youtube.com/watch?v=OBL8OJUWmsI

    Gl!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-08
      • 2014-04-19
      • 2011-09-12
      • 1970-01-01
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多