Note that there are some explanatory texts on larger screens.

plurals
  1. POIphone - cellForRowAtIndexPath behaving weirdly when scrolling down and up
    text
    copied!<p>I would like to get a TableView with different elements on the accessoryView, depending on the section. Everything works fine, but when I scroll down to section 2 and then scroll up again to section 0, the rows in section 0 have switchers. Could you please help me finding out what I'm doing wrong? <code></p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger sectionIndex = [indexPath section]; static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; NSDictionary *dictionary; NSArray *array; NSString *cellValue; UISwitch *switchView; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } switch (sectionIndex) { case 0: cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; break; case 1: cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; break; case 2: switchView = [[UISwitch alloc] initWithFrame:CGRectZero]; cell.accessoryView = switchView; [switchView setOn:NO animated:NO]; [switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; [switchView release]; break; default: break; } dictionary = [searchArray objectAtIndex:indexPath.section]; array = [dictionary objectForKey:@"advancedSearch"]; cellValue = [array objectAtIndex:indexPath.row]; cell.textLabel.text = cellValue; return cell; </code></pre> <p>}</p> <p></code></p>
 

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