Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The first problem with your code is that you create cell's subviews each time cell is requested - if you scroll your table to and fro your cell will have a bunch of those subviews - certainly that's not good. You must create cell subviews only once - when you create the cell and after that only set appropriate values to them:</p> <pre><code>const int kRightViewTag = 100; const int kRightLabelTag = 200; ... if (cell == nil) { // Create everything here cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SectionsTableIdentifier] autorelease]; cell.textLabel.textColor = [UIColor whiteColor]; UIView *rightUIView = [[UIView alloc] initWithFrame:CGRectMake(160, 0, 160, cell.frame.size.height)]; rightUIView.tag = kRightViewTag; [rightUIView setBackgroundColor:[UIColor greenColor]]; [rightUIView release]; // Do not forget to release object you allocate!! UIView *leftUIView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 160, cell.frame.size.height)]; [leftUIView setBackgroundColor:[UIColor redColor]]; [leftUIView release]; // Do not forget to release object you allocate!! UILabel *rightLabel = [[UILabel alloc] initWithFrame:leftUIView.bounds]; rightLabel.tag = kRightLabelTag; [rightUIView addSubview:rightLabel]; [rightLabel release]; } // Setup values here UILabel* rightLabel = (UILabel*)[[cell viewWithTag:kRightViewTag] viewWithTag:kRightLabelTag]; rightLabel.text = @"dummy"; </code></pre> <p>The second thing is you do not set label's frame anywhere (I've fixed that above) so it is likely has zero-sized frame and that's why you cannot see it.</p> <p>The 3rd problem is that you allocate views but don't release them - so they just leak. Do not forget that if you create some objects using alloc, new or copy then you're responsible for releasing them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload