【发布时间】:2011-06-29 09:00:32
【问题描述】:
我想知道是否有人知道在延迟后取消选择表格视图的方法?
我正在使用deselectRowAtIndexPath 方法。我只想在取消选择之前突出显示一秒钟。
谢谢!
【问题讨论】:
标签: ios objective-c swift uitableview uitableviewrowaction
我想知道是否有人知道在延迟后取消选择表格视图的方法?
我正在使用deselectRowAtIndexPath 方法。我只想在取消选择之前突出显示一秒钟。
谢谢!
【问题讨论】:
标签: ios objective-c swift uitableview uitableviewrowaction
我可以使用 [tableView deselectRowAtIndexPath:indexPath animated:YES]; 做到这一点
另一种方法是:
[self performSelector:@selector(deselect:) withObject:self afterDelay:0.33];
然后创建一个调用deselectRowAtIndexPath的方法deselect
【讨论】:
deselect 方法应该采用一个参数(您将 self 作为参数传递),这意味着它至少会被称为deselect:。
如果您想要完成的是:点击一行,查看突出显示,突出显示消失,您可以:
在didSelectRowAtIndexPath
//after you do whatever your doing when a row is selected
UITableViewCell *cell [tableView cellForRowAtIndexPath:indexPath];
[cell setSelected:NO];
如果我没有误解你的话,这将产生你想要的效果。
【讨论】:
[self performSelector:@selector(deselect:) withObject:self afterDelay:0.33];
要在取消选择表格视图单元格时添加轻微延迟,您需要在tableView(_:didSelectRowAt:) 中添加以下内容:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.33) {
self.deselectRow(at: indexPath, animated: true)
}
【讨论】: