I'm new to iOS development.. and I'm stuck with the problem of changing table view height dynamically.
I know that I should do it in tableView:heightForRowAtIndexPath:
method but[cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height
content is always returning one small value 18.0
..
My cell layout looks like this:
with such scene:
Here is the code in my TableViewController:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MYModel *model = [[MYModel alloc] initWithDictionary:[self.items objectAtIndex:indexPath.row]];
NSString *reuseIdentfier = @"textCell";
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentfier forIndexPath:indexPath];
[self configureCell:cell forRowAtIndexPath:indexPath withData:model];
return cell;
}
I'm using SDWebImage (https://github.com/rs/SDWebImage) for loading images and here is the configure cell method below:
- (void)configureCell:(MyTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath withData:(MYModel *)model
{
ANOTHERModel *itemCollection = [[ANOTHERModel alloc] initWithDictionary:model.collection];
cell.collectionTitle.text = [itemCollection title];
cell.collectionOwner.text = [NSString stringWithFormat:@"by %@", itemCollection.ownerName];
[cell.collectionOwnerAvatarView setImageWithURL:[NSURL URLWithString:itemCollection.ownerAvatar] placeholderImage:[UIImage imageNamed:@"gravatar.png"]];
// make circle avatars
CALayer *layer = [cell.collectionOwnerAvatarView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:cell.collectionOwnerAvatarView.frame.size.height/2];
// type
NSString *imageName = [model.type stringByAppendingFormat:@".png"];
UIImage *typeImage = [UIImage imageNamed:imageName];
[cell.typeIconView setImage:typeImage];
// title and description
cell.itemTitle.text = [model title];
cell.itemDescription.text = [model description];
[cell.itemDescription setTextAlignment:NSTextAlignmentLeft];
[cell.itemDescription setLineBreakMode:NSLineBreakByWordWrapping];
[cell.itemDescription setNumberOfLines:0];
// always returns 18.0
NSLog(@"%f", [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height);
}
I really don't understand why.. please help!
Thanks!