2017-03-02 71 views

回答

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 
} 

分享您的全部源代码,更好地帮助

+0

我想自动交换这些自定义单元..不是由用户本身。 – akshay

0

如果你想在UITableView重新排序行。看看UITableView中实施的两位代表。它们是:tableView:canMoveRowAtIndexPath:moveRowAtIndexPath:toIndexPath:

另请参阅tutorial,其中显示了如何实现它。

+0

通过使用这种方法用户可以交换单元格,但我希望它会自动交换..我有两个单元只是想与另一个替换。感谢您的快速回复。 – akshay

0

与tableview delegates一起,使用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 
} 
相关问题