views:

1524

answers:

4

I have this really weird bug. When I scroll down my table view, down to a section I called "description", the cells in this section won't be displayed. Instead, the title of the section is repeated again and again. It sounds like whoever is in charge of the screen display in the iPhone does not find anything to display and let what was on the screen before (and it is the title of the section because I scrolled down).

If I take a screenshot, there just is a black background instead of the cell. (As a new user, I can not use image tag... The screen shot is here : dl.free.fr/rj7ts3DJc ).

This bug does not happened in the simulator, but only in a real device.

Did anyone ever meet this kind of thing ? Could you guess where the problem is ?

A: 

Try changing the word description to something else. Objective C classes use the word description to signify a method where an object can describe itself with an NSString. If changing the name fixes it, your bug is something to do with that.

You can see description at work like this:

NSString *aString = [[NSString alloc] initWithFormat:@"hi"];
NSLog(@"%@", [aString description]);
nevan
Good guess, I tried but does not change anything...
Unfalkster
The section header "Description" should not cause any trouble. It's a normal string!
lostInTransit
A: 

It's probably related to cell caching. Please post your code in "[tableView cellForRowAtIndexPath]". You are probably caching (for reuse) the cell in the wrong way.

Pablo Santa Cruz
I tried to answer my own question but the post doesn't seem to show up... I assume it will take some time, meanwhile I could tell that indeed I am caching for reuse my cell, with a cell identifier, and as it is the only one, when I dequeue the cell I assume it is ok and just return it.But anyway, this code works well with my others cell...We just have to wait for my post to show up...
Unfalkster
Are you using dequeueReusableCellWithIdentifier:? The problem could have something to do with that. Guess your post didn't show up. Try editing the question and posting the code there instead.
lostInTransit
A: 

Thank you for your replies, I will put the code here. But remember that my code works well for all other cells, so it had to be related with the specific content of this cell, but it is just some text in a UILabel...

Do not hesitate to check out the video I have made, it is a very curious behaviour for the iPhone, have your even seen that ? dl.free.fr/rlQmFyWS0

Here is the code for cellForRowAtIndexPath: method, just the part concerned by the description cell :

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's 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 keep investigating here

Unfalkster
A: 

I have found the solution... It was obvious but still...

My UILabel has a size greater than 2048 px. We are not allowed to use size larger than that, that's the reason the rendering is so weird.

This thread stackoverflow.com/questions/773386/inserting-various-views-into-uiscrollview has already dealt with that issue.

Unfalkster