0

我从未有过使用AFNetworking的应用程序的问题,因为我有20像素显示,但现在我的应用程序崩溃,因为我想将imagewithURL设置为150 Imageviews,如果我评论该线路一切正常,这是我的代码:AFNetworking +许多imageviews =崩溃 - >收到内存警告

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,但同样的问题,请一些建议!谢谢:)

回答

1

你正在创建150米的UIImageViews和用图像数据填满你的记忆和崩溃你的应用程序。

你应该让一个UITableView或UICollectionView并使用内置的内存处理

dequeueReusableCellWithReuseIdentifier

,显示在屏幕上的图像,只重用之一,在小区的相同的UIImageView 。不创建150个图像,即只需要一个。

一些快速google搜索让我这个教程: https://www.youtube.com/watch?v=OBL8OJUWmsI

胃肠!