【发布时间】:2015-12-21 22:09:22
【问题描述】:
我的应用程序在 iPhone4 上因频繁使用 5 到 10 分钟而崩溃。
我在应用程序本身中有一些图像,有内部 SQLite 文件,图像名称存储在 sqlite 表中并从名称中使用。
还可以通过 url (NSURL) 从在线数据库中获取一些图像。在线数据库图像使用 SDWebImage 框架加载到 UIImageView 中。但仍然收到“收到内存警告”并且应用程序被终止
我已经用仪器检查了它显示图像获取更多数据并导致崩溃
从数据库中获取图像名称数组并将图像加载到 UICollectionViewCell 中的 UIImageView
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell1 = [self->collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
for (UIImageView *lbl in cell1.contentView.subviews)
{
if ([lbl isKindOfClass:[UIImageView class]])
{
[lbl removeFromSuperview];
}
}
imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, cell1.frame.size.width, cell1.frame.size.width)];
imgView.backgroundColor = CLEAR_COLOR;
imgView.contentMode = UIViewContentModeScaleAspectFit;
UIImage *imv = [UIImage imageNamed:(NSString *)mArray_FeatIcon[indexPath.item]];
imgView.image = imv;
[cell1.contentView addSubview:imgView];
imv = nil;
return cell1;
}
从 UICollectionView 中的 weburl 加载图像
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell1 = [cvGallery dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
for (UIImageView *lbl in cell1.contentView.subviews)
{
if ([lbl isKindOfClass:[UIImageView class]])
{
[lbl removeFromSuperview];
}
}
UIImageView * imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, cell1.frame.size.width, cell1.frame.size.height)];
imgView.backgroundColor = [UIColor clearColor];
NSString *urlString = [[NSString stringWithFormat:@"%@",mArrThumbUrl[indexPath.item]] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[imgView setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"logo.png"]];
[cell1.contentView addSubview:imgView];
return cell1;
}
由于声誉低,无法添加乐器的屏幕截图。提前致谢。
【问题讨论】:
-
您好,欢迎来到 SO。您能否附上一些日志,以便更好地告诉我们问题出在哪里?
-
@James,将日志显示为“收到内存警告”。它最多到达 4 次,然后应用程序崩溃。并在 Xcode 中获得警报 -> 应用程序终止:由于内存压力
标签: ios memory memory-leaks crash uiimage