从 segue 返回时,UITableViewCells 不会取消选择
我有一个 UITableView,其中包含 Storyboard 中的单元格,以及将单元格连接到另一个视图的 segue。
当您选择一个单元格时,它会显示单元格选择动画(在我的例子中将单元格变成灰色)并将另一个视图推到屏幕上。但是当您返回到表格视图时,取消选择动画根本不显示(与选择动画相反)。由于我只是使用转场,所以我希望默认情况下会处理这个问题。
有什么办法可以强制它显示取消选择动画吗?
I have a UITableView with cells in a Storyboard, and a segue connecting the cells to another view.
When you select a cell it displays the cell selection animation (turning the cell gray, in my case) and pushes the other view onto the screen. But when you return to the tableview, the deselection animation doesn't show at all (the reverse of the selection animation). Since I'm just using a segue, I expected this to be taken care of by default.
Is there any way to force it to show the deselection animation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您的视图控制器是
UITableViewController
的子类,并且clearsSelectedOnViewWillAppear
设置为YES
(这是默认值),这将自动处理。在您的情况下,您可以按照与 UITableViewController 相同的方式执行此操作。取消选择
-viewWillAppear:
中选定的行。This would be handled automatically if your view controller was a subclass of
UITableViewController
andclearsSelectedOnViewWillAppear
was set toYES
(which is the default value).In your case you can do this the same exact way that
UITableViewController
does it. Deselect the selected row in-viewWillAppear:
.不确定 Segues 的使用,但我经常想在视图控制器出现时刷新数据。但是,如果重新加载表,则会清除所选行。这是我用来维护选定行并在返回时显示取消选择动画的一些代码。也许这对您有帮助,所以我将其发布在这里。
Not sure about the use of segues but I often want to refresh data when a view controller appears. If you reload the table however, you clear the select row. Here is some code I use to maintain a selected row and show the deselect animation when returning. It may be the case that this may help you so I will post it here.
确保您正在调用
viewWill...
和viewDid...
方法的super
实现Make sure you are calling the
super
implementations of theviewWill...
andviewDid...
methods对于斯威夫特 3
For Swift 3
快速更新:-
Swift Update :-
更好的 Swift 更新:
Better Swift update: