Multiline Message Cut Off by Table Cell...

Discussion in 'iPhone/iPad Programming' started by ArtOfWarfare, Nov 16, 2009.

  1. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #1
    I tried asking for help from someone in person, but they weren't willing to stand up and come and look, so instead I had to print out the paper explaining it below. Rather than take the screen shots again and upload them, I figured I'd just upload the PDF of what I printed.

    On the left I have two very similar screen shots... the top shows the program running with font size 20, while the bottom shows the program running with font size 14 (which is what it's set to in the example code.) Notice that the middle cell on the top one cuts off "game!!" while the middle cell on the bottom one properly includes it.

    On the right, I have what I believe is all the relevant snippets of code

    Basically my issue is that neither the text view nor the cell is setting the height properly. Therefor, there seems to be either:
    a.) an issue with how I'm using the sizeWithFont:constrainedToSize:lineBreakMode method
    b.) an issue with how the above method calculates height.

    I suspect the issue lies in the fact that sizeWithFont:constrainedToSize:lineBreakMode is calculating it's height using something other than a UITextView. What makes me think this? Because it includes "lineBreakMode" as one of its parameters. Text wrapping can't be set on a UITextView... but it can be set on a UILabel. The dumb part is that UILabel will ignore anything related to wrapping and instead the only values that make a difference are whether (and where) to truncate, or to simply crop.
     

    Attached Files:

  2. macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #2
    Why not just resize the sext to fill size. The tableview has a property that allows that.
     
  3. thread starter macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    What property of UITableView allows you to set the text to fill size?

    I believe you're referring to a property of UILabel (namely, a UILabel within a UITableViewCell)... however the UILabel cannot have multiple lines of text, so instead I have to use the UITextView. The UITextView however, doesn't have any similar property.

    Either I'm an idiot or someone at Apple mixed things up when they decided to give the line wrapping to a class that couldn't use it and neglected giving it to the one that could.

    (If someone could just write the one line of code I would need to fix this... I've been researching for hours now within Apple docs and various forms, I'm getting very frustrated now...)
     
  4. macrumors member

    Joined:
    Jul 2, 2009
    #4
    Why does UILabel have this property then?

     
  5. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    I looked at your source code. One obvious mistake is that you are adding the textview to the cell every time that cellForRowAtIndexPath is called. You should only add the text view one time, when the cell is created, not when it's dequeued.

    Here's how I've always debugged this problem: print out the height returned from heightForRowAtIndexPath. The way you have the code written with everything in one expression makes it difficult to debug. Spread out that expression into multiple expressions so you can see all the intermediate results. I think you need to make the textview have an autoResizingMode of flexible width and flexible height. Also, for debugging purposes you can add the willDisplayCell callback and inspect the cell's properties when it's about to draw. Also, the width of the textview isn't the same as the width you're passing to sizeWithFont in heightForRowAtIndexPath, which is one of the usual reasons this doesn't work.
     
  6. thread starter macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #6
    Wow, thanks for pointing that out.
    I made the mistake of assuming UILabel was always limited to a single line. By getting rid of the whole chunk of code making a UITextView and just using the UILabel that comes with the cell, my code is a lot simpler and now it seems to actually work.

    This is a very good point and I'll keep it in mind in the future when dealing with custom subviews in a UITableViewCell.
     

Share This Page