. , (- ) ?
: cellForRowAtIndexPath. : () , , () , , , , , , - .
(a), , . (b) .
:
@property(strong,nonatomic) NSMutableDictionary *images;
self.images = [@{} mutableCopy];
- (void)imageWithPath:(NSString *)path completion:(void (^)(UIImage *, NSError *))completion {
if (self.images[indexPath]) {
return completion(self.images[indexPath], nil);
}
NSURL *imageURL = [NSURL URLWithString:path];
NSURLRequest *request = [NSURLRequest requestWithURL:imageURL];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (!error){
UIImage *image = [UIImage imageWithData:data];
self.images[indexPath] = image;
completion(image, nil);
} else {
completion(nil, error);
}
}];
}
, cellForRowAtIndexPath.
UIImage *image = self.images[indexPath];
if (image) {
[cell.CellImg setBackgroundImage:image forState:UIControlStateNormal];
} else {
[cell.CellImg setBackgroundImage:nil forState:UIControlStateNormal];
[self imageWithPath:img completion:^(UIImage *image, NSError *error) {
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
}
, ... , . , , , indexPath.
: , , , . , . ( , ). ( iOS 5+, ), subview...
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight =