开发者

iPhone deselect row after delay

I was wondering if anyone was aware 开发者_如何学Goof 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!


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


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜