My app needs to display huge number of images(about 2000) in a UITableView. Basically, I use the following code to construct my UITableViewCell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
// Some Operations...
NSString *path = [self.dataArray jk_objectWithIndex:indexPath.row];
UIImage *img = [UIImage imageWithContentsOfFile:path];
cell.imageView.image = img;
return cell;
}
This works but when the tableview loads, memory increase fast and it seems that all the images is loaded to the memory.
Is there any good ideas to deal with this? I just want to save the memory.
BTW, anyone knows what the common way is to achieve this need? I think loading all the images to memory is the stupidest way... And the code I initial rows of tableview is the following:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (!_isLoading) {
return self.dataArray.count; // about 2000... That's terrible
} else {
return 0;
}
}
Thanks!