Reputation: 14886
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
Upvotes: 1
Views: 1700
Reputation: 4583
I came across this post when I was having a similar issue on iOS5 so I'll leave a few lines on how i solved mine in case anyone else is stuck. On my cells, I had bumped up the font size of the text and it was then cutting off the text although there was plenty of space left for it to fit. I had
adjustsFontSizeToFitWidth:NO
so it was truncating the text with a ...
The way I fixed it was simply made the overall width and height of the cell's frame larger and that did the trick.
CGRect frame = CGRectMake(0, 0, SCREEN_WIDTH, height);
UIView *view = [[UIView alloc] initWithFrame:frame];
cell.frame = frame;
Hopefully it helps someone in the future
good luck
Upvotes: 0
Reputation:
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;
Upvotes: 1
Reputation: 4352
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.
Upvotes: 1