Akshaykumar Maldhure Akshaykumar Maldhure - 11 days ago 6
Objective-C Question

Image not loading in tableview in iOS 10 on first time, but after scroll?

I am getting problem while displaying images in tableview in iOS 10, but same code works bellow iOS 10, I have added snippet of my code bellow. Please help.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"InboxTableViewCell";

InboxTableViewCell *cell = (InboxTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[InboxTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
[cell setBackgroundColor:[cellColors objectAtIndex:indexPath.row]];
[cell.profileImageView setImage:[UIImage imageNamed:@"profile.jpg"]];

return cell;
}


And in the cell I am making image circular

#import "InboxTableViewCell.h"
@implementation InboxTableViewCell

- (void)awakeFromNib {
[super awakeFromNib];

// Initialization code


}

-(void)layoutSubviews{
self.profileImageView.layer.cornerRadius = self.profileImageView.frame.size.width/2;
self.profileImageView.clipsToBounds=YES;
[super layoutSubviews];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

@end

Answer

Finally I got the answer and I am my own question now. we just have to wright it in drawRect method and thats it.

Happy Coding...

-(void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    self.profileImageView.layer.cornerRadius=_profileImageView.frame.size.width/2;
    [_profileImageView setClipsToBounds:YES];
    [_profileImageView layoutIfNeeded];
    [_profileImageView setNeedsDisplay];
}
Comments