Ios TableView与内存警告
我使用的是xcode 5和ios 7。当我滚动到表的末尾时,从服务器异步加载数据(图50-100kb)。10次尝试后出现内存警告。。。。使用GCD进行异步下载。如何解决这个问题而不丢失滚动内容的平滑度?与GCD合作 CellCreate:Ios TableView与内存警告,ios,uitableview,asynchronous,memory-warning,Ios,Uitableview,Asynchronous,Memory Warning,我使用的是xcode 5和ios 7。当我滚动到表的末尾时,从服务器异步加载数据(图50-100kb)。10次尝试后出现内存警告。。。。使用GCD进行异步下载。如何解决这个问题而不丢失滚动内容的平滑度?与GCD合作 CellCreate: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *c
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellID = [NSString stringWithFormat:@"Cell%i",indexPath.section];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
/*
First section simple text cell
Second section hard cells
*/
if(cell == nil)
{
switch (indexPath.section)
{
case 0:
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
break;
}
case 1:
{
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
break;
}
default:
{
break;
}
}
}
if (indexPath.section == 1)
{
NSInteger index = indexPath.row;
ModelInfo* model = [arrayModelInfo objectAtIndex:index];
[(CustomCell*)cell setContent:model];//Update subview in cell with parametrs model
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
自定义单元格设置内容
[self.CustomConentView.imageView setImage:model.image];
[self.CustomConentView.label setText:model.name];
下载:
NSInteger serverOffset = 0;
.....
dispatch_async(queueDownloadData, ^{
[self backgroundDownloadRecometedProducts];
});
.....
- (void) backgroundDownload
{
Network* network = [[LMNetwork alloc] init];
[network getRecomendedProductOffset:serverOffset
Success:^(id JSON) {
dispatch_async(queueDownloadData, ^{
recomentedProductsOffset += 10;
[self parse:JSON];
});
}];
}
- (void) parse: (id) JSON
{
NSArray* result = [JSON objectForKey:@"result"];
for (NSDictionary* parametrs in result)
{
ModelInfo* model = [[ModelInfo alloc] initWithDictionary:parametrs];
[arrayModelInfo addObject:model];
dispatch_async(self.queueDownloadImages, ^{
[self downloadImageForName:model.thumbnail Tag:[arrayModelInfo indexOfObject:model]];
});
}
dispatch_async(dispatch_get_main_queue(), ^{
[tableViewContent reloadData];
});
}
- (void) downloadImageForName: (NSString*) imageName Tag: (NSInteger) tag
{
Network* network = [[Network alloc] init];
[network downloadImageWithName:imageName
ImageTag:tag
Success:^(UIImage *image, NSInteger tag) {
ModelInfo* model = [arrayModelInfo objectAtIndex:tag];
model.image = image;
dispatch_async(dispatch_get_main_queue(), ^{
[tableViewContent reloadData];
});
}];
}
在服务器中的网络类post请求中,我使用了AFNetworking请发布一些代码,说明如何创建单元格以及如何异步加载数据。在arrayModelInfo中保存所有下载的图像。如果删除内存和缓存中的图像,当滚动到单元格图像被删除时该怎么办?