Reputation: 6940
I have UICollectionView, when i tap collection cell UITableView appear. I want that UITableViewCell's image be round, and when i first load this table all images are round, when i select in and move inside detail controller, then switch back they are still round. But, when i enter UITableView (down from UICollectionView), then press "Back" button to see UICollectionView again, then press UICollectionView cells, it shows me UITableView with visible "square (default) image" cell. Why i say visible? Well, when i scroll down, new cells are round again as they should be. Why this nasty bug appear? There is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
myCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UILabel *labelText = (UILabel *)[cell viewWithTag:1000];
labelText.text = [[self.listOfPlaceDetails objectAtIndex:indexPath.row] objectForKey:@"name"];
if (cell == nil){
cell = [[myCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[cell.imageView setImageWithURL:[NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageFirst"]] placeholderImage:[UIImage imageNamed:@"noPhoto.png" ]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){
UIImage *resizedImage = [image resizedImageWithBounds:CGSizeMake(66, 66)];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.imageView.image = resizedImage;
cell.imageView.layer.cornerRadius = cell.imageView.bounds.size.width /2.0f;
cell.imageView.clipsToBounds = YES;
cell.separatorInset = UIEdgeInsetsMake(0, 82, 0, 0);
}];
self.stringToPass = [[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"description"];
return cell;
}
Why images square when user get back to first view and then again switch to UITableView?
Upvotes: 1
Views: 525
Reputation: 4168
Since the images you fetch resized to definite dimensions of 66x66, you can set the cornerRadius
irrespective of the image being set.
- (void)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
…
cell.imageView.layer.cornerRadius = 33.0;
cell.imageView.layer.masksToBounds = YES;
…
return cell;
}
Upvotes: 1
Reputation: 2725
I think that the problem is related with this:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
Try that for setting the image inside the cell (are you using SDWebImage)?
// Set the corner radius and clip to bounds before setting the image
[cell.imageView.layer setCornerRadius:cell.imageView.frame.size.width/2];
cell.imageView.clipToBounds = YES;
// I'm using SDWebImage
[cell.imageView setImageWithURL:[NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageFirst"]] placeholderImage:[UIImage imageNamed:@"noPhoto.png"]];
Hope it helps!
Upvotes: 3