大家好,我有一个UITableView
我AfNetworking
用来加载非常大的图像的。但是,当它didreceivememorywarning
被击中时,我的应用程序就会崩溃。这是我的代码:
在AFNetworking+uiimageview.m
我按照建议添加了这个:
@implementation AFImageCache
- (id)init
{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveMemoryWarning)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
}
return self;
}
- (void)didReceiveMemoryWarning
{
DebugLog(@"AFNetworking DID RECEIVED MEMORY WARNING ");
[self removeAllObjects];
}
我在uitableview中的代码如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
TousCell *tvCell;
NSArray *nib;
nib = [[NSBundle mainBundle] loadNibNamed:@"TousCell" owner:self options:nil];
tvCell = [nib objectAtIndex:0];
tvCell.lbltitle.text=[[dict valueForKey:@"message"]objectAtIndex:i];
[tvCell.imgPhoto setImageWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"http://test.com/%@", [[dict valueForKey:@"photo"]objectAtIndex:i]]]];
可能是我cells
每次都在重新创建吗?但我确信它链接到图像下载,因为图像有时很大(大小约为 2 - 3 Mb?)。