UITableView: How to make the UITableViewCellAccessoryDetailDisclosureButton appear on selection?

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

Answers


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


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.


Need Your Help

Android: how to detect touch location on ImageView if the image view is scaled by matrix?

android matrix touch imageview scale

I set OnTouchListener of an ImageView and implement onTouch method, but if the image is scaled using matrix, how do I calculate the location of the touch?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.