Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you create new label and add it to cell each time cell is being reused. To fix that you must create your label only when your cell is created:</p> <pre><code>if (cell == nil){ cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier: CellIdentifier] autorelease]; CGRect textViewRect = CGRectMake(10.0, 0.0, 250, 25); UILabel *textView = [[UILabel alloc] initWithFrame:textViewRect]; textView.tag = kLabelTag; textView.font = [UIFont systemFontOfSize:12.0]; textView.textColor = [UIColor blackColor]; textView.highlightedTextColor = [UIColor whiteColor]; textView.textAlignment = UITextAlignmentRight; [cell.contentView addSubview:textView]; [textView release]; CGRect imageRect = CGRectMake(270.0, 15, 16, 16); UIImageView *icon = [[UIImageView alloc] initWithFrame:imageRect]; icon.image = [myDictionary objectForKey:@"color-icon"]; icon.highlightedImage = [myDictionary objectForKey:@"gray-icon"]; [cell.contentView addSubview:icon]; [icon release]; } </code></pre> <p>And after that you can get your label from cell using tag property you've assigned:</p> <pre><code>UILabel *textView = (UILabel*)[cell.contentView viewWithTag:kLabelTag]; textView.text = [myDictionary objectForKey:@"name"]; </code></pre> <p>same logic also applies to setting up your icon imageview if it varies in different cells</p> <p>Also have a look at components standard UITableViewCell already provides (depending on its cell style) - there's already UIImageView and UILabels there and you can set your custom properties to them and use them without creating extra components </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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