может быть что-то вроде этого, при условии, что ваши значки находятся в каталоге документа:
#define DOCUMENTS_DIRECTORY [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
//inside - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys:indexPath, @"indexPath", @"image1.png", @"imageName", nil];
[NSThread detachNewThreadSelector:@selector(loadIcon:) toTarget:self withObject:d];
//
- (void)iconLoaded:(NSDictionary*)dict {
[icons replaceObjectAtIndex:[[dict objectForKey:@"index"] intValue] withObject:[UIImage imageWithData:[dict objectForKey:@"imageData"]]];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[dict objectForKey:@"indexPath"]]];
}
- (void)loadIcon:(NSDictionary*)dict {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *filePath = [DOCUMENTS_DIRECTORY stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", [dict objectForKey:@"imageName"]]];
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
[self performSelectorOnMainThread:@selector(iconLoaded:) withObject:[NSDictionary dictionaryWithObjectsAndKeys:[dict objectForKey:@"indexPath"], "indexPath", imageData, @"imageData", nil] waitUntilDone:YES];
[pool drain];
}
вам нужно будет отслеживать, для каких ячеек вы загружаете изображение, поэтому вы не пытаетесь загрузить его, пока оно уже загружается. могут быть небольшие синтаксические ошибки, так как я не компилировал их, просто написал от руки.
icons
- это NSMutableArray
, содержащий UIImage для каждой клетки