我想在collectionView(_:cellForItemAt :)里面的表部分标题索引或部分标题标题

时间:2018-06-11 05:55:06

标签: ios swift uitableview uicollectionview

我在UITableViewCell中实现了一个集合视图。我希望collectionView(_:cellForItemAt:)

中的表部分标题索引或标题标题

这是我的表格视图代码:

extension ContentCatVCViewController : UITableViewDataSource {

    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return categories[section]
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return categories.count
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CategoryRow
        print("table row index:: \(indexPath.row)")
        return cell
    }

    func tableView(_ tableView: UITableView, willDisplayHeaderView view:UIView, forSection: Int) {
        if let headerTitle = view as? UITableViewHeaderFooterView {
            headerTitle.textLabel?.textColor = UIColor.clear
        }
    }
}

这是我的表格单元格代码:

extension CategoryRow : UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "videoCell", for: indexPath) as! VideoCell
        cell.layer.borderWidth = 1
        cell.layer.borderColor = UIColor(red:222/255, green:225/255, blue:227/255, alpha: 1).cgColor

        return cell
    }

}

如何获取 tableView(_:titleForHeaderInSection:) 功能中的collectionView(_:cellForItemAt:)。请帮忙。

1 个答案:

答案 0 :(得分:0)

在cellForRowAt方法中,您正在加载CollectionView。意味着您正在获取要加载CollectionViews的IndexPath。因此indexPath.section将成为每个CollectionView的头索引。

相关问题