I have a table view (SlackTextViewController
) with a custom UITableViewCell
which contains an UIImageView
and a UITextView
. I use SDWebImage
for caching and setting images.
This is my cellForRowAtIndexPath
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"CommentsCell";
CommentsCell *cell =(CommentsCell *) [self.tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:identifier owner:self options:nil];
cell = [nib objectAtIndex:0];
}
commentsModel =(CommentsModel *)commentsListArray[indexPath.row];
if (commentsModel.hasImage) {
cell.imageHeight.constant=150;
cell.photoImageView.hidden = NO;
NSString *imageUrl = commentsModel.commentImage;
[cell.photoImageView setShowActivityIndicatorView:YES];
[cell.photoImageView setIndicatorStyle:UIActivityIndicatorViewStyleGray];
cell.photoImageView.contentMode = UIViewContentModeScaleAspectFill;
[cell.photoImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
} else {
cell.imageHeight.constant=0;
cell.photoImageView.hidden = YES;
cell.textview.text=commentsModel.comments;
[cell.textview sizeToFit];
}
cell.transform = self.tableView.transform;
return cell
}
When the view controller is opened for the first time, the imageView's content mode is somehow set to ScaleAspectFit
and when I scroll up and down for a couple of times, the content mode is properly set to ScaleAspectFill
.
Initial content mode state:
After scrolling up and down some:
Another weird thing that happens is, when I present a UIAlertController
, the content mode of the imageView suddenly animates to ScaleAspectFill
as you can see in below video:
https://www.youtube.com/watch?v=OT3bUR4CR5c&feature=youtu.be
- I haven't changed the content mode to
ScaleAspectFit
anywhere in the code accidentally. - I checked the view hierarchy to see that there are no changes in the imageView's width and height, and I am not changing its frame anywhere.
- I tried setting the content mode in
prepareForReuse
method of the custom cell. - I tried setting image in main thread.
None of the above is solving the issue. Any help would be appreciated. Thanks.