3

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!

Parth
  • 2,682
  • 1
  • 20
  • 39
gabaum10
  • 3,769
  • 3
  • 48
  • 89

3 Answers3

10

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

csch
  • 1,455
  • 14
  • 12
  • 1
    +1 this is what i would use, although according to what you have there, the `deselect` method should take a parameter (you're passing `self` as a parameter), which means it'd be called `deselect:`, at the least. – Dave DeLong Feb 17 '11 at 20:38
0

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.

Andy Obusek
  • 12,614
  • 4
  • 41
  • 62
DVG
  • 17,392
  • 7
  • 61
  • 88
0
[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)
}
Parth
  • 2,682
  • 1
  • 20
  • 39