Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to save your images in an <code>NSArray</code> or similar because you must configure the cells in <code>cellForRowAtIndexPath:</code>. Whenever the table view reloads it will call <code>cellForRowAtIndexPath:</code> and it expects the cells to be returned with suitable content for the supplied index path.</p> <p>You could setup each cell in your <code>showStream:</code> but it's much easier just to save all the images there and then <code>reloadData</code> at the end. Then you don't need to do any pre-setup of the table view to tell it how many rows + sections it has, do any visibility checks (to ensure the cells are on display) for the rows you're trying to update, ... - reuse the functionality supplied by the table view...</p> <p>Something more like:</p> <p><code>showStream:</code> (store all your new views into an array, photoList)</p> <pre><code>self.photoList = [[NSMutableArray alloc] init]; NSDictionary* photo = [stream objectAtIndex:i]; PhotoView* photoView = [[PhotoView alloc] initWithIndex:i andData:photo]; photoView.delegate = self; [self.photoList addObject photoView]; </code></pre> <p><code>cellForRowAtIndexPath:</code> (create the cell if required, clean the cell, add the photo view)</p> <pre><code>if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; [cell.contentView addSubview:[self.photoList objectAtIndex:indexPath.row]]; </code></pre>
 

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