Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>so <code>// complex stuff</code> means adding UIViews. </p> <p>I make an example for an UIImageView. Since you don't show the complex stuff you have to adopt it on your own.</p> <p>your code looks like this:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } if ([self.hats count] &gt; 0) { UIImageView *imageView = [[UIImageView....]; [cell.contentView addSubView:imageView]; [imageView setImage:foo]; [imageView release]; } return cell; } </code></pre> <p>refactor your code that it looks like this:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; UIImageView *imageView = [[UIImageView....]; [cell.contentView addSubView:imageView]; imageView.tag = 42; [imageView release]; } if ([self.hats count] &gt; 0) { UIImageView *imageView = [cell viewWithTag:42]; [imageView setImage:foo]; } return cell; } </code></pre> <p>et voila, your tableview is responsive. Because you create the subviews exactly one time for each cell. And when the cell isn't used anymore and goes into the reuse bin the subviews stay with it. </p> <p>And if you need 4 imageViews in one cell and 8 in another, you add 8 imageviews when you create the cell and give them a frame of CGRectZero and of course a different tag for each view.<br> If you need them you show them, if you don't need them you set the image to nil and the frame to zero.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. 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