views:

893

answers:

3

I am using UITableViewCellStyleValue2 and UITableViewStyleGrouped.

Let's start with some code (it's not 100% complete, but I have tried to include the code needed to hopefully decipher what I am doing, and maybe doing wrong):

#define CELL_FONTSIZE 15.0f
CGSize textSizeValue2 = {207.0f, 9999.0f};

if ([value isEqual: CELL_4]) {
     CGSize   size = [cell4String sizeWithFont:[UIFont boldSystemFontOfSize:CELL_FONTSIZE] constrainedToSize:textSizeValue2 lineBreakMode:UILineBreakModeWordWrap];
     size.height += CELL_HEIGHT;          // top and bottom margin
     result = MAX(size.height, 44.0f);  // at least one row

For this particular cell, the result for the height comes out to 214 both for 3.0 and 3.1

Here's the code for the cell:

static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
    cell.textLabel.numberOfLines = 0;
    cell.detailTextLabel.numberOfLines = 0;
    cell.clearsContextBeforeDrawing;

if ([value isEqual: CELL_4]) {
        cell.textLabel.text = @"About";
        cell.detailTextLabel.text = cell4String;

So basically, for 3.0 and 3.1 the exact same thing is happening, but when running the app in 3.0 simulator, the last line seems to get cut off if the cell.detailTextLabel.numberOfLines has more than three lines of text. The strange thing is that the text is just cut off, but the cell is drawn at the correct height in 3.0, there's just a big blank whitespace underneath the cell.

Anyone know why this is different between 3.0 and 3.1 ? I know I am using a beta of Xcode, but it's pretty strange that it works in the beta and not in 3.0 because, as far as I can see, I am not doing anything too crazy, but something basic.

Thanks

+1  A: 

Well, I don't have an answer or solution. But I just wanted to point out I'm facing the same issues. I thought I'd let you know that you're not the only one, that's probably worth something.

I'm using Xcode 3.1.3 with the 3.0 iPhone SDK installed (not a beta). The "blank space" appears both in the simulator and on the device both running firmware 3.0. I haven't tried a more recent version.

Yannick Compernol
Thanks for the feedback. It's to hear I am not the only one, although the error seems strange and definitely fixable. Those cells are important in my app so now that 3.1 is out it's not a problem. I req. 3.0 anyway so req. 3.1 should be a big problem I hope. But def let me know if you find out how to fix it.
Canada Dev
+1  A: 

You need to determine the size of the text area that is rendered with the text in it. To do this use a function similar to below and then set that for the row height of the tableviewcell in question. Adjust your font size accordingly. I added a pad of 20 to give it some space to breathe

     UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:14.0];
 CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
 CGSize labelSize = [[detailValues objectAtIndex:indexPath.section] sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

 labelHeight = labelSize.height + 20;
tekn0wledg
As you can see from my code, that's not the issue.
Canada Dev
A: 

Hi. Have the same problem. Have somebody solved the problem? Think it's possible to use custom cells, but it's not easy make them such flexible as native ones.

slatvick
I have made a custom cell class, which does all the drawing itself. Besides working around this issue/bug, it also is faster than using controls in the cell or using the default cell. The custom cell implements something like an ICellKnowsHeight interface which is used to get the height of the cell in the table-delegate/datasource.
Yannick Compernol