简体   繁体   English

我想要表部分标题索引或collectionView(_:cellForItemAt :)中的标题标题

[英]I want the table section header index or section header title inside collectionView(_:cellForItemAt:)

I have implemented a collection view within a UITableViewCell. 我已经在UITableViewCell中实现了一个集合视图。 I want the table section header index or header title inside collectionView(_:cellForItemAt:) 我想要表部分标题索引或collectionView(_:cellForItemAt:)标题

Here is my table view code: 这是我的表格视图代码:

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
        }
    }
}

Here is my table cell code: 这是我的表格单元格代码:

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
    }

}

How to get the tableView(_:titleForHeaderInSection:) inside collectionView(_:cellForItemAt:) function. 如何在collectionView(_:cellForItemAt:)函数内获取tableView(_:titleForHeaderInSection:) Please help. 请帮忙。

In cellForRowAt method you are loading CollectionView. 在cellForRowAt方法中,您正在加载CollectionView。 Means you are getting IndexPath where you are loading CollectionViews. 表示您在加载CollectionViews的位置获取IndexPath。 So indexPath.section will be your header index for each CollectionView. 因此indexPath.section将是每个CollectionView的标头索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM