gpt4 book ai didi

ios - 我想要 collectionView 中的表节标题索引或节标题标题(_ :cellForItemAt:)

转载 作者:行者123 更新时间:2023-11-28 07:46:43 24 4
gpt4 key购买 nike

我在 UITableViewCell 中实现了一个 Collection View 。我想要 collectionView(_:cellForItemAt:)

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

这是我的表格 View 代码:

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。意味着您在加载 CollectionView 的位置获取 IndexPath。所以 indexPath.section 将是每个 CollectionView 的标题索引。

关于ios - 我想要 collectionView 中的表节标题索引或节标题标题(_ :cellForItemAt:),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50791225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com