如何在tableview中相互交换两个自定义单元格? [英] How to swap two custom cells with one another in tableview?

查看:53
本文介绍了如何在tableview中相互交换两个自定义单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 tableview 中实现了两个自定义单元格.现在我想将这两个自定义单元格相互替换.如何实现这一目标?

I have implemented two custom cells in the tableview.Now I want to replace these two custom cells with one another. How to achieve this?

推荐答案

与 tableview 委托一起,使用 moveRow(at: <IndexPath>, to: <IndexPath>),移动你的以编程方式(自动)行,无需用户交互.

Along with tableview delegates, use moveRow(at: <IndexPath>, to: <IndexPath>), to move your row programatically (automatically), without user interaction.

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
}

这篇关于如何在tableview中相互交换两个自定义单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆