Я загружаю изображения в виде таблицы, которые соответствуют тексту ячейки, поэтому каждое изображение отличается. Когда пользователь прокручивается вниз, iOS должен вручную перезагрузить каждое изображение с SSD, поэтому прокрутка очень изменчив. Как кэшировать изображения или препятствовать тому, чтобы ячейки представления таблицы нуждались в воссоздании? У других проблемы были решены с помощью imageNamed:
, так как iOS автоматически кэширует ваши изображения, но я загружаю изображения из каталога документов, а не в пакет приложений. Что мне делать? Благодарю.Кэширование изображений в UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [issues count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSDictionary *dic = [self.issues objectAtIndex:indexPath.row];
cell.text = [dic objectForKey:@"Date"];
cell.imageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/issues/%@/cover.png", documentsDirectory, [dic objectForKey:@"Directory Name"]]];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 150;
}
Checkout UIImageLoader. Он делает именно то, что вы хотите, и только два файла для добавления в xcode. Это также очень легко понять, и в репо есть два отличных примера. https://github.com/gngrwzrd/UIImageLoader – gngrwzrd