0

I've encountered a strange issue. At first it happened on one app when I set several view to equal width and equal leading\trailing constraints. Everything worked fine on iOS 8.x but on iOS 7.x I saw that the last view's trailing constraint went missing.

It wasn't a big deal but now I have a big problem. I am working on a new application and one of the features is chat with a user. I have set two possible table cells (incoming message and outgoing message). Each cell contains a UITextView to hold the text (it needs to identify links and phone numbers). The textView's size depends on the content text and the size of the "bubble" changes according to it's size. Again, on iOS 8.x all works perfectly!!! SWEET! And again... iOS 7.x fails to do it! without a visible reason, texts are getting truncated, words are disappearing and line breaks occur out of no-where. I have no implementation that adjusts the textView's size... it's all autolayout based.

How can I fix this. I searched for an answer but I'm not even sure how to describe it. Help? Anyone?

Edit:

Had a day off yesterday :) Thank for the replies...

I have an image of the constraints I set up... Constraints

Now, in my tableView's heightForRowAtIndexPath, I return a height calculated by the message object:

- (CGFloat)height {
    
    CGRect rect = [self.body boundingRectWithSize:CGSizeMake(210.0, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName:[UIFont fontWithName:@"OpenSans" size:15.0]}
                                          context:nil];
    return rect.size.height + kCellHeightDelta;
}

I don't want to uses someone else's library, no matter how good it is. My client has his desires for what he wants it to look like and would rather put more time into it, doing what's right for the project, than copy-paste someone else's implementation without understanding what I'm missing. But I truly am grateful.

  • Please share your constraints. – koen Mar 16 '15 at 16:25
  • Are you calculating the cell heights in iOS7? There is no cell auto layout in iOS7. You have to do the height sizing yourself and return the right size in `heightForRowAtIndexPath`. – Rory McKinnel Mar 16 '15 at 16:29

1 Answers1

0

Cell layout in iOS7 requires quite a bit of hand holding to get the cell heights correct. You have to calculate the heights using an off screen prototype cell, unless you know the exact heights by other mechanisms, and return this height in heightForRowAtIndexPath.

Size classes also adds an extra dimension to this as prototype cells created with dequeueCellWithIdentifier do not have the size class defined in them.

The following discussion has links to the mechanism to use and a neat solution to the issues of dealing with size classes and manual cell height calculation.

Offscreen UITableViewCells (for size calculations) not respecting size class?

Community
  • 1
  • 1
Rory McKinnel
  • 7,730
  • 2
  • 15
  • 28