当TableView单元格沿向上方向滚动时,不会从父tableView调用子集合视图委托方法

时间:2018-07-19 07:50:05

标签: ios swift uitableview uicollectionview delegates

我的情况是: 我有一个tableView,并且在tableView内部有一个CollectionView。

以防万一:当我从上向下滚动tableView时,将调用子collectionView的Delegate方法。

不起作用的情况::当我将表View Bottom向上滚动时,未调用子集合View Delegate方法。

我不确定在将tableView Bottom滚动到Up时为什么未调用委托方法。

以下是我的用于设置CollectionView的委托的代码:

ProductListCell是我的tableViewCell的名称。

extension ProductListCell {

    func setCollectionViewDataSourceDelegate<D: JTAppleCalendarViewDataSource & JTAppleCalendarViewDelegate>(_ dataSourceDelegate: D, forRow row: Int) {

        CalenderCollectionView.calendarDelegate = dataSourceDelegate
        CalenderCollectionView.calendarDataSource = dataSourceDelegate
        CalenderCollectionView.tag = row
        CalenderCollectionView.setContentOffset(CalenderCollectionView.contentOffset, animated:false)
        CalenderCollectionView.reloadData()
    }

    var collectionViewOffset: CGFloat {
        set { CalenderCollectionView.contentOffset.x = newValue }
        get { return CalenderCollectionView.contentOffset.x }
    }
}

必需的TableView方法:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    print("will display cell")
    if((indexPath.row+1)/10 == self.pageNumber && self.pageNumber < self.TotalPages){
        self.pageNumber+=1
        self.ApiCallforCategoryData()
    }

    guard let tableViewCell = cell as? ProductListCell else { return }
    tableViewCell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row)
    tableViewCell.collectionViewOffset = storedOffsets[indexPath.row] ?? 0
}


func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    print("did end displaying cell")
    guard let tableViewCell = cell as? ProductListCell else { return }
    storedOffsets[indexPath.row] = tableViewCell.collectionViewOffset
}

请让我对它的工作方式或为什么这样工作的原因有所了解。让我知道是否需要添加更多代码。

0 个答案:

没有答案