gabaum10
gabaum10

Reputation: 3827

iPhone deselect row after delay

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!

Upvotes: 3

Views: 1259

Answers (3)

Dracula
Dracula

Reputation: 3090

[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)
}

Upvotes: 0

DVG
DVG

Reputation: 17480

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.

Upvotes: 0

csch
csch

Reputation: 1455

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

Upvotes: 10

Related Questions