Strange device error: UITableView cell content not showing
I have this strange error. When I scroll through my table view, down to what I call "description", the cells in that section will not appear. Instead, the section heading is repeated over and over. It looks like someone in charge of the screen display in the iPhone finds nothing to display and allows what was on the screen before (and that's the title of the section because I scrolled down).
If I take a screenshot, there is a black background instead of the cell.
This error does not occur in the simulator, but only in the real device.
Has anyone ever come across this kind of thing? Could you guess where the problem is?
a source to share
I found a solution ... It was obvious, but still ...
My UILabel is over 2048px. We are not allowed to use a size larger than that, which is the reason for the rendering is so strange.
This thread stackoverflow.com/questions/773386/inserting-various-views-into-uiscrollview has already covered this issue.
a source to share
Try changing the word description to something else. Objective C classes use word description to denote a method in which an object can describe itself using an NSString. If the name change fixes this, your error is related to this.
You can see the description at work like this:
NSString *aString = [[NSString alloc] initWithFormat:@"hi"];
NSLog(@"%@", [aString description]);
a source to share
Thanks for your answers, I'll put the code here. But remember, my code works well for all other cells, so it had to be linked to the specific content of that cell, but this is just some text in the UILabel ...
Feel free to check the video I made, this is a very curious behavior for iPhone, have you even seen it? dl.free.fr/rlQmFyWS0
Here is the code for the cellForRowAtIndexPath: method, only the description cell related part:
case 3: // A big cell containing the description
{
// Try to find an already allocated cell with the description (note : there is only one description cell per table so no need to check the content...)
UITableViewCell * descriptionCell = [tableView dequeueReusableCellWithIdentifier:kTextCellIdentifier];
if (descriptionCell == nil) {
// As a frame, use the description label one plus a little margin for the height
descriptionCell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, self.descriptionText.frame.size.height + (2*kCellInset)) reuseIdentifier:kTextCellIdentifier] autorelease];
descriptionCell.selectionStyle = UITableViewCellSelectionStyleNone;
// The descriptionText UILabel has been previously initialized properly by tableview:heightForRowAtIndexpath: method
[descriptionCell.contentView addSubview:self.descriptionText];
}
return descriptionCell;
And here is the part where I initialized the descriptionText field:
// Customize row height for each cell
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 3) {
CGSize realSize;
if (self.descriptionText != nil) {
// the description has been previously initialized
realSize = descriptionText.frame.size;
}
else {
// We need to dynamically resolve the height for the description zone
NSString * desc = (NSString *)[product objectForKey:@"description"];
UILabel * descLabel = [[UILabel alloc] initWithFrame:CGRectZero];
// Unlimited number of lines
descLabel.numberOfLines = 0;
descLabel.text = desc;
// Set a preferred width and anything for the height
realSize = [descLabel sizeThatFits:CGSizeMake(tableView.frame.size.width - (2*kCellInset), 1)];
// Take the opportunity to set the frame with the correct values
descLabel.frame = CGRectMake(kCellInset, kCellInset, realSize.width, realSize.height);
self.descriptionText = descLabel;
[descLabel release];
}
return (realSize.height + (2*kCellInset));
}
else {
return kImageCellHeight;
}
return 0;
}
Any guess would be more than welcome ... I am continuing my investigation here
a source to share