我在tableview中实现了两个自定义单元格。现在我想要将这两个自定义单元格相互替换。怎么做到这一点?
答案 0 :(得分:0)
实现以下tableview方法并在其中编写代码
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// return boolean value for a specific or all cells, you want to enable movement
}
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
// Handle array element movement along with your row/cell
}
分享您的完整源代码更好的帮助
答案 1 :(得分:0)
如果您想重新排序UITableView
中的行。看看在UITableView
。
它们是:tableView:canMoveRowAtIndexPath:
和moveRowAtIndexPath:toIndexPath:
。
另请参阅tutorial,了解如何实施。
答案 2 :(得分:0)
与tableview委托一起使用moveRow(at: <IndexPath>, to: <IndexPath>)
,以编程方式(自动)移动行,而无需用户交互。
tblTabel.moveRow(at: <IndexPath>, to: <IndexPath>)
// Tableview Delegates
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// return boolean value for a specific or all cells, you want to enable movement
}
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
// Handle array element movement along with your row/cell
}