Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to preserve selected status for UITableViewCell when scrolling off and back on screen
    primarykey
    data
    text
    <p>I have custom UITableViewCell cells in a UITableView. When a cell is selected by the user and the cell is scrolled off the screen, and then scrolled back into the screen, the selected cell is blank.</p> <p>I know that I need to set all values in the cell as the cells are reused, but I have not been able to figure this one out. </p> <p>Iamge 1 represents a user selecting the cell: </p> <p><img src="https://i.stack.imgur.com/j4wBv.png" alt="Table when a cell is selected"></p> <p>Image 2 represents when the cell is scrolled off screen and back on screen <img src="https://i.stack.imgur.com/kvgyC.png" alt="Table when the cell is scrolled off screen and back on screen"></p> <p>(Ignore the fact the images are blurred, simply protecting my customers data)</p> <p><em>Note: I want to be able to select the table, don't suggest to remove the ability to highlight the cell. I actually want to be able to see the blue cell when scrolling a selected cell back into the screen.</em></p> <p>Any help will be appreciated.</p> <p>EDIT: Adding some code:</p> <pre><code>// Define a property to keep track of the cell that was selected last using the NSIndexPath @property (nonatomic, strong) NSIndexPath *lastSelectedIndexPath; /////// - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Keeps track of the lastest selected entry self.lastSelectedIndexPath = indexPath; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { IPCSearchResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; [self configureCell:cell atIndexPath:indexPath]; return cell; } - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { // Cast the cell to the custom cell IPCSearchResultTableViewCell *searchResultCell = (IPCSearchResultTableViewCell *)cell; // RepositoryIndex is a coredata object with information MyCoreDataEntity *entity = [self.fetchedResultsController objectAtIndexPath:indexPath]; searchResultCell.label1.text = entity.attribute1; searchResultCell.label2.text = entity.attribute2; searchResultCell.label3.text = entity.attribute3; searchResultCell.label4.text = entity.attribute4; } </code></pre> <p><strong>*NOTE: The code above now seems to be working. I am not experiencing this issue anymore and don't know why *</strong></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. 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