Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView not updating correctly when scrolling
    primarykey
    data
    text
    <p>I am writing a UITableView that contains 2 sections. When the table first loads all the cells are displaying the correct info, but when I start scrolling up and down, cells detailedTextLabel and accessoryType are being refreshed incorrectly, such that some cells that should only contain a detailedTextLabel also contain an accessory, and cells that should only contain an accessory also contain a detailedTextLabel.</p> <p>Inside <code>cellForRowAtIndexPath:</code> I am using nested switch/case statements to apply the correct values to the cells in their respective section/row. As far as i can tell the logic in these statements is correct, so is it possible that the value of <code>cell</code> variable is inccorect when updating? </p> <p>The table loads correctly but after scrolling accessoryType and detailedTextLabel gets mixed up. </p> <p><a href="http://www.flickr.com/photos/57059764@N07/5263568952/" rel="nofollow">Click for link to screen shots of the table.</a></p> <p>Here is the code inside of my UITableViewController subclass: </p> <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [sectionNames count]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. NSArray *headingsSection = [cellTitles objectAtIndex:section]; return [headingsSection count]; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [sectionNames objectAtIndex:section]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { self.tableView.allowsSelection = YES; static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.text = [[cellTitles objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; cell.textLabel.textColor = [UIColor blackColor]; cell.textLabel.font = [UIFont boldSystemFontOfSize:15]; switch (indexPath.section) { case 0: cell.detailTextLabel.text = [NSString stringWithFormat:@"%d%%", [[assistSettingsArray_glob objectAtIndex:indexPath.row] intValue]]; break; case 1: switch (indexPath.row) { case 0: cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; break; case 1: cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; break; case 2: if (defaultAssistOn) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } break; } break; } return cell; } </code></pre>
    singulars
    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.
 

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