views:

355

answers:

2

Hi all. I'd like to have all the rows on my table view use UITableViewCellAccessoryNone (e.g. no button on the right) unless they are selected, at which point I want to use UITableViewCellAccessoryDetailDisclosureButton. E.g. only one row (or none if there's no selection) has the button at a time.

Is this possible? Doing the usual thing of implementing accessoryTypeForRowWithIndexPath doesn't seem to work dynamically - e.g. it only gets called once regardless of what's selected.

Thanks

+1  A: 

If you change the contents of a cell, you'll want to call -reloadRowsAtIndexPaths:withRowAnimation: on your tableview.

Ben Gottlieb
Thanks Ben! That works great.
Ben Clayton
+1  A: 

Note for others trying this.. the accessoryTypeForRowWithIndexPath delegate method is now depreciated, you'll get this message if you try it:

WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in . Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release.

Instead, implement the setSelected method in your UITableViewCell subclass.. e.g.

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

[super setSelected:selected animated:animated];

// Configure the view for the selected state

if (selected) {
    self.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
} else {
    self.accessoryType = UITableViewCellAccessoryNone;
}

..then use the reloadRowsAtIndexPaths:withRowAnimation method as described above.

Ben Clayton