简体   繁体   English

在 UITableView 中默认启用重新排序控制,而不处于编辑模式

[英]Enable Reorder Control in UITableView as default without being in edit mode

I am currently working on a solution where I need to have a UITableView by default in reorder mode without having a delete button but could enable the delete button when necessary.我目前正在研究一种解决方案,在该解决方案中,默认情况下我需要在重新排序模式下使用UITableView ,而没有删除按钮,但可以在必要时启用删除按钮。 I am just curious if this is even achievable in iOS?我只是好奇这是否可以在 iOS 中实现? If so what should be my approach for this?如果是这样,我的方法应该是什么?

In my opinion your table view should always be in edit mode.在我看来,您的表格视图应该始终处于编辑模式。

To make the reorder controls appear you should implement UITableViewDataSource methods要使重新排序控件出现,您应该实现 UITableViewDataSource 方法

tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool

and

tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)

If you don't want the delete button to be displayed you can do that by implementing如果您不希望显示删除按钮,您可以通过实现

tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle

and return.none by default or.delete when you want to have the button displayed.和 return.none 默认情况下或.delete 当您想要显示按钮时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM