Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For your other cells, you need to reuse the cell either:</p> <pre><code>static NSString *CellIdentifier = @"CellS"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } </code></pre> <hr> <h3>EDIT for Updated Question:</h3> <p>You need to know how "cell reusing" works. As for your updated code, it said only row 1 needs the subviews like image, right? So you need add it outside of the <code>if (cell == nil){}</code> snippet, like the code below: </p> <pre><code>static NSString *CellIdentifier = @"CellS"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } if (indexPath.row == 1) { UIImage* likesimage = [UIImage imageNamed:@"likespic"]; CGRect frameimg = CGRectMake(7, 5, likesimage.size.width, likesimage.size.height); likesbutton = [[UIButton alloc] initWithFrame:frameimg]; [likesbutton setBackgroundImage:likesimage forState:UIControlStateNormal]; likesbutton.backgroundColor = [UIColor clearColor]; [cell addSubview:likesbutton]; label3 = [[UILabel alloc] initWithFrame:CGRectMake(20, 2, 100, 20)]; label3.textColor = [UIColor colorWithRed:61.0/255.0 green:113.0/255.0 blue:154.0/255.0 alpha:1.0]; label3.backgroundColor = [UIColor clearColor]; label3.font = [UIFont fontWithName:@"Helvetica-Bold" size:12]; label3.adjustsFontSizeToFitWidth = YES; [cell addSubview:label3]; } </code></pre> <p><strong>Note</strong>: It's better to create a new cell instance like what you did for row 0, cause it's only need to be created once.</p>
    singulars
    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