[英]Transfer data from table view cell inside a collection view cell, to another collection view cell [with picture!]
我正在开发一个应用,其中我陷入了收藏视图单元格与其中包含的表格视图之间的困境。
我的第一个集合视图单元格包含一个带有表视图单元格的表视图。 每个表视图单元格都包含保存的数据,并且通过选择一个单元格,应该发生两种情况。
另一方面是表视图存储在容器视图类中。 我不确定是否要这样做,但是不确定要传递变量的一层。
到目前为止,这是我遇到的问题
tableViewDidselectCode
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let header = LoadHeaderView()
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SavedTableViewCell
header.titleString = cell.taskLabel.text!
header.descriptionString = cell.clientLabel.text!
}
我该如何传递给
self -> ContainerView -> collectionCell[0] -> CollectionView -> collectionCell[1] -> tableView -> header?
您的表视图依赖于父集合视图单元格。 这意味着您需要在实例化时将集合视图单元格的引用传递给表视图。 我会制定协议。
protocol myTableViewCellDelegate {
func updateMyCollectionViewCell
}
extension myCollectionViewCell: myTableViewCellDelegate {
func updateMyCollectionViewCell {
// update whatever you need to here
}
}
extension myCollectionTableViewDelegate: UITableViewDelegate {
// ...
func collectionView(_ collectionView: UICollectionView,
willDisplay cell: UICollectionViewCell,
forItemAt indexPath: IndexPath) {
// instantiate table view
// pass self to tableview *as weak reference*
myTableView.customDelegate = self
}
//...
}
extension myTableViewDelegate: UITableViewDelegate {
//...
func tableView(_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath) {
// instantiate table view cell
// assuming you're not using custom cell class
tableCell.updateMyCollectionViewCell()
// if you are using custom cell class then the tableViewDelegate
// will need to pass collectionView reference on to the cells
}
}
希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.