I’m trying to use a UITableViewController and replace the editing mode button (usual default is ‘Delete’) with a custom view.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
... (other code) ...
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.tag = pd.itemId;
UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
cell.editingAccessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];
//cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
When I try to swipe, nothing happens. What’s strange is that if I uncomment the cell.accessoryView line, my image appears fine. This makes me think that it something about the editing settings that is wrong? But nowhere online or in documentation can I find what those settings are supposed to be.
Thanks!
Update: Ah. okay, so I gave myself an ‘edit’ button for the UITableView nav controller. Now I can toggle all the cells into edit mode, and my accessory appears. What does ‘swiping’ a cell do then?
Kurt
canEditRowAtIndexPath should return YES if you set the editingAccessoryView and want it to appear. Plain accessoryView is visible while the table is not in editing mode. However the swiping of the cell shows the delete confirmation button which isn’t the editingAccessoryView, and messing with
without calling [super willTransitionToState:state]; will lead to unexpected behavior (your cell will not leave the UITableViewCellStateShowingDeleteConfirmationMask state). If you can manage calling super and not allowing the cell to show the delete confirmation button, then you’re done.