I have a UISwitchView on every tableview cell, and would like to allow the cells to be reordered. The problem is when I set setEditing=true on the table view, the accessory (switchview) disappears. Is there a way to keep both?
EDIT
static NSString *CellIdentifier = @"Edit Sources Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
NSUInteger row = [indexPath row];
Source *source = [self.sources objectAtIndex:row];
cell.textLabel.text = source.name;
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
switchView.tag = row;
cell.accessoryView = switchView;
[switchView setOn:source.switchedOn animated:NO];
[switchView addTarget:self action:@selector(switchChangedForSource:) forControlEvents: UIControlEventValueChanged] ;
UITableViewCell has an additional property,
editingAccessoryView, for a view that is displayed when the cell is in editing mode.I don’t know if you can assign the same UISwitch instance to both the
accessoryViewandeditingAccessoryViewproperties, or if you will need to make two instances. (A view can only have one parent at a time, but the UITableViewCell is actually doing the work of displaying the view, so it may be smart enough to handle this case.)