繁体   English   中英

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

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

我已经在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
    }

}

如何在collectionView(_:cellForItemAt:)函数内获取tableView(_:titleForHeaderInSection:) 请帮忙。

在cellForRowAt方法中,您正在加载CollectionView。 表示您在加载CollectionViews的位置获取IndexPath。 因此indexPath.section将是每个CollectionView的标头索引。

暂无
暂无

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

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