Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>EDIT - using images as a background view</strong></p> <p>Given your comments on my answer it seems like you want to display images in the background view of your cells. It is not clear if these images are compiled into your app as resources or downloaded from a service. Regardless, you can use the same <code>UIImage</code> instance in multiple <code>UIImageView</code> instances. So as you create your cells, you can create a new <code>UIImageView</code> on the fly for use as the background view and then set the <code>image</code> property to the appropriate <code>UIImage</code> based on the cell's indexPath.</p> <p>If the images are compiled into your app then <code>[UIImage imageNamed:@""]</code> uses an iOS implemented cache and will perform well. If you are downloading images (presumably on a background thread) then you will need to implement a disk and/or memory cache for your image data.</p> <p><strong>ORIGINAL ANSWER</strong></p> <p>When you configure your cell in <code>tableView:cellForRowAtIndexPath:</code> use the cell identifier to use the built-in caching of the <code>tableView</code> to cache cells with the various background views for you.</p> <p>Something like:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *singleCellID = @"single"; static NSString *firstCellID = @"first"; static NSString *middleCellID = @"middle"; static NSString *lastCellID = @"last"; NSString *cellID = nil; NSInteger section = [indexPath section]; NSInteger row = [indexPath row]; NSInteger maxRow = [tableView numberOfRowsInSection:section] - 1; UIColor *color = nil; if (maxRow == 0) { // single cell cellID = singleCellID; } else if (row == 0) { // top cell cellID = firstCellID; } else if (row == maxRow) { // bottom cell cellID = lastCellID; } else { // middle cell cellID = middleCellID; } UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath]; if (cell == nil) { if (cellID == singleCellID) { // create single cell cell = ... cell.backgroundView = ... } else if (cellID == firstCellID) { // create first cell cell = ... cell.backgroundView = ... } else if (cellID == lastCellID) { // create last cell cell = ... cell.backgroundView = ... } else { // create middle cell cell = ... cell.backgroundView = ... } } } </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