我开发了一个项目,用户在画布上绘制图像,我使用 CoreData 将其存储在文件中,我有一对多的关系,称为文件夹到文件。所以这里都是图片。我从文件中检索图像,根据我的表格单元格高度调整大小并将其显示在表格上。显示后,我想缓存图像。
我在文件夹单元格上也有一些标签,它们为我提供了一些关于我的文件的信息,我会即时更新这些信息。我还滑动单元格以将其标记为完成并将其移动到单元格的底部。
我还会根据用户查询的方式在不同的视图中显示相同的文件图像。
我想知道最好的方法,我通过网络阅读,它们有很多方法,GCD,NSOperationQueues 等等。
哪种方法最适合我。
我想展示一些代码
- (UITableViewCell *)tableView:(FMMoveTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
FolderCell *tableCell = (FolderCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (tableCell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FolderCell" owner:self options:nil];
tableCell = [nib objectAtIndex:0];
}
NSMutableArray *categoryArray = [[self.controller fetchedObjects]mutableCopy];
Folder *category = [categoryArray objectAtIndex:[indexPath row]];
[tableCell configureCellWithNote:category]; //This function is written in my FolderCell.m function
}
return tableCell;
}
-(void)configureCellWithNote:(Folder *)category
{
self.category = category;
UIImage *image1 = [UIImage imageWithData:category.noteImage];
CGSize newSize;
if(image1.size.width == 620 && image1.size.height == 200)
{
newSize = CGSizeMake(300, 97);
}
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image1 drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.notesImage.image = newImage;
}
所以这里发生的是 configureCellWithNote 需要很多时间,因为它正在调整图像大小。请帮助我决定如何解决这个性能问题。
问候拉吉特