Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deselecting the table view row when returning

I followed Luke Redpath's suggestion here - Selected UItableViewCell staying blue when selected - to deselect the row when returning to the original table view, but I can't get it working. In fact the method doesn't get triggered.

- (void)viewDidAppear:(BOOL)animated {   [super viewDidAppear:animated];   [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES]; } 

I suspect this is because the class isn't a UITableViewController, but a UIViewController with the tableView as a property connected up to the NIB.

How would I get the same behavior - ie deselecting when returning?

like image 337
cannyboy Avatar asked Oct 20 '10 11:10

cannyboy


People also ask

What is Table View delegate?

func tableView(UITableView, willDisplay: UITableViewCell, forRowAt: IndexPath) Tells the delegate the table view is about to draw a cell for a particular row. func tableView(UITableView, indentationLevelForRowAt: IndexPath) -> Int. Asks the delegate to return the level of indentation for a row in a given section.

What is deselectRow?

deselectRow(at:animated:)Deselects a row that an index path identifies, with an option to animate the deselection.


1 Answers

why you just don't deselect it in the delegate method

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];  } 
like image 63
ahmad Avatar answered Sep 22 '22 08:09

ahmad