iPhone deselect row after delay

1.2k Views Asked by At

I was wondering if anyone was aware of a way to deselect a table view after a delay?

I am using the deselectRowAtIndexPath method. I just want the highlighting to show up for a second before deselecting it.

Thanks!

3

There are 3 best solutions below

1
On BEST ANSWER

I was able to do that using [tableView deselectRowAtIndexPath:indexPath animated:YES];

Another way to do this would be:

[self performSelector:@selector(deselect:) withObject:self afterDelay:0.33];

and then create a method deselect that calls deselectRowAtIndexPath

0
On

If what you are trying to accomplish is: Tap a row, see highlight, highlight goes away you can:

In didSelectRowAtIndexPath

//after you do whatever your doing when a row is selected
UITableViewCell *cell [tableView cellForRowAtIndexPath:indexPath];
[cell setSelected:NO];

This will produce the effect you're looking for if I haven't misunderstood you.

0
On
[self performSelector:@selector(deselect:) withObject:self afterDelay:0.33];

Swift version:

To add a slight delay when deselecting a tableview cell, you need to add the following to tableView(_:didSelectRowAt:):

DispatchQueue.main.asyncAfter(deadline: .now() + 0.33) {
   self.deselectRow(at: indexPath, animated: true)
}