AFNetworking +许多图像视图=崩溃->收到内存警告 [英] AFNetworking + Many imageviews = Crash -> Received memory warning
问题描述
使用AFNetworking我的应用程序从未遇到过问题,因为我希望显示20个imageview,但是现在我的应用程序崩溃了,因为我想将imagewithURL设置为150个Imageviews,如果我评论说这行没事,这是我的代码:
I 've never had problems with my app using AFNetworking, because I had like 20 imageview to show , but now my app crash because I want to set imagewithURL to 150 Imageviews, if I commented that line all is ok, this is my code:
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,但是是同样的问题,请提出一些建议!,谢谢:)
I put a dispatch_async, but is the same problem, please some advices!, thanks :)
推荐答案
您正在创建150个UIImageViews并填充它们使用imagedata破坏了您的内存并导致应用崩溃。
You are creating 150 UIImageViews and are filling them up with imagedata which mess up your memory and crashes your app.
您应该制作一个UITableView或UICollectionView并使用内置的内存处理程序
You should make a UITableView or UICollectionView and use the built in memory handler
dequeueReusableCellWithReuseIdentifier
dequeueReusableCellWithReuseIdentifier
,以在屏幕上显示图像并在单元格中仅重复使用一个相同的UIImageView。不创建150个uiimageviews,即只需要一个。
, to show the images on the screen and reuse only one and the same UIImageView in the cell. Not create 150 uiimageviews that is, only one is needed.
一些快速谷歌搜索使我进入了本教程:
https://www.youtube.com/watch?v=OBL8OJUWmsI
Some fast googling got me to this tutorial: https://www.youtube.com/watch?v=OBL8OJUWmsI
Gl!
这篇关于AFNetworking +许多图像视图=崩溃->收到内存警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!