问题
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.
}
I put a dispatch_async, but is the same problem, please some advices!, thanks :)
回答1:
You are creating 150 UIImageViews and are filling them up with imagedata which mess up your memory and crashes your app.
You should make a UITableView or UICollectionView and use the built in memory handler
dequeueReusableCellWithReuseIdentifier
, 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.
Some fast googling got me to this tutorial: https://www.youtube.com/watch?v=OBL8OJUWmsI
Gl !
来源:https://stackoverflow.com/questions/30514038/afnetworking-many-imageviews-crash-received-memory-warning