I have a TableView that load images from my Url, everything's fine. The problem is when I scroll down or up, the images become bigger in the cells. Sometime it become bigger than the cell it's self.
I have tried every thing, but it is not working, I am sitting the View mode to Aspect fit, but still have the same problem.
Her is my code:
static NSString *cellIdentifier = @"Cell";
CellView *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (!cell) {
cell = [[CellView alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
ListOfObjects *listObjects;
cell.accessoryType = UITableViewCellAccessoryNone;
listObjects = [listArray objectAtIndex:indexPath.row];
cell.userName.text = userName;
ListOfObjects *venue = ((ListOfObjects * )self.listArray[indexPath.row]);
NSString *one = listObjects.theUserId;
NSURL *myUrl = [NSURL URLWithString:one];
if (listObjects.image) {
cell.imageView.image = listObjects.image;
} else {
// set default user image while image is being downloaded
cell.imageView.image = [UIImage imageNamed:@"second58.png"];
// download the image asynchronously
[self downloadImageWithURL:myUrl completionBlock:^(BOOL succeeded, UIImage *image) {
if (succeeded) {
// change the image in the cell
cell.imageView.image = image;
// cache the image for use later (when scrolling up)
venue.image = image;
}
}];
}
Can any one give me an idea about it?
Maybe you can resize image frame:
[self downloadImageWithURL:myUrl completionBlock:^(BOOL succeeded, UIImage *image) {
if (succeeded) {
cell.imageView.image = image;
cell.imageView.frame = your.frame;
}
}];
if you cache the image, you should set it's frame when you use it, not only when it finished download
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.