Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What it sounds like you are doing is, in your cellForRowAtIndexPath method, you are setting up your UITableViewCells with some labels in them and each time, you are making the labels from scratch. What you should be doing is, setting up the labels if you are making a new cell, and then setting the values on the labels outside of this to fully utilize the ability to reuse table view cells to improve performance of scrolling the table view.</p> <p>The key method is <code>-viewWithTag:</code> which, along with the <code>tag</code> property on UIView you can use to find a specific subview.</p> <p>A little sample code:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"MyCellIdentifier"; UITableViewCell *cell = (WHArticleTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UILabel *firstLabel = nil; UILabel *secondLabel = nil; UILabel *thirdLabel = nil; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; firstLabel = [[[UILabel alloc] initWithFrame: CGRectMake(0.0, 0.0, 20.0, 20.0)] autorelease]; firstLabel.tag = 1; [cell addSubview:firstLabel]; secondLabel = [[[UILabel alloc] initWithFrame: CGRectMake(20.0, 0.0, 20.0, 20.0)] autorelease]; secondLabel.tag = 2; [cell addSubview:secondLabel]; thirdLabel = [[[UILabel alloc] initWithFrame: CGRectMake(40.0, 0.0, 20.0, 20.0)] autorelease]; thirdLabel.tag = 3; [cell addSubview:thirdLabel]; } else { firstLabel = (UILabel *)[cell viewWithTag:1]; secondLabel = (UILabel *)[cell viewWithTag:2]; thirdLabel = (UILabel *)[cell viewWithTag:3]; } firstLabel.text = @"First Label's Text Here"; secondLabel.text = @"Second Label's Text Here"; thirdLabel.text = @"Third Label's Text Here"; return cell; } </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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