-
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PJJokeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TextJokeCell"];
if (cell == nil) {
cell = [[PJJokeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TextJokeCell"];
}
PJJoke *joke = self.jokes[indexPath.row];
cell.time.text = joke.time;
cell.text.text = joke.text;
if (joke.imgurl && joke.imgurl.length > 0) {
SDImageCache *imageCache = [SDImageCache sharedImageCache];
if ([imageCache diskImageExistsWithKey:joke.imgurl]) {
[cell.image setImage:[imageCache imageFromDiskCacheForKey:joke.imgurl]];
} else {
[cell.image setImageWithURL:[NSURL URLWithString:joke.imgurl]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if (error == nil && image && joke && tableView) {
joke.imageWidth = image.size.width;
joke.imageHeight = image.size.height;
[tableView beginUpdates];
[tableView endUpdates];
}
}];
}
}
return cell;
} -
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
PJJoke *joke = self.jokes[indexPath.row];
SDImageCache *imageCache = [SDImageCache sharedImageCache];
if ([imageCache diskImageExistsWithKey:joke.imgurl]) {
UIImage * = [imageCache imageFromDiskCacheForKey:joke.imgurl];
joke.imageWidth = image.size.width;
joke.imageHeight = image.size.height;
}
return [PJJokeTableViewCell heightForJoke:self.jokes[indexPath.row]];
}
网友评论