gpt4 book ai didi

swift - 如何在单个 TableViewcell 的不同部分拥有不同的图像,并将 Collection View 放置在 tableviewCell 内

转载 作者:行者123 更新时间:2023-11-30 11:09:53 27 4
gpt4 key购买 nike

I want different images under different heading

//ViewController.swift
var categories = ["Good Afternoon","Daily Mixes","Bollywood Gems","Daily Mixes","Bollywood Gems","Bollywood Romantic","Pop","Trending Now","Top Charts","Saavn Originals","New Releases","Top Playlists","Radio Stations","Editorial Picks" ]

func numberOfSections(in tableView: UITableView) -> Int {
return categories.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return categories[section]
}
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! CategoryRowTableViewCell
return cell
}


// custom.swift

@IBOutlet weak var pic: UIImageView!

@IBOutlet weak var text: UILabel!

func execute()
{
print("This is working")
pic.layer.cornerRadius = pic.frame.size.width/2
pic.clipsToBounds = true
print("working")

}


// CategoryRowTableViewCell.swift

let main : [String] = ["black forest","butterscotch","Truffle","a","b","c","d","e","j","k","u","q","s","z"]


@IBOutlet weak var collect: UICollectionView!





func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 14
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collect.dequeueReusableCell(withReuseIdentifier: "videocell", for: indexPath) as! custom
cell.execute()
cell.pic.image = UIImage(named : main[indexPath.row])
cell.text.text = main[indexPath.row]
print(cell.text.text!)

return cell

}

我有一个 TableView ,因为我有一个 TableView 单元格。我有 TableView 单元格的不同部分。在该单元格中,有一个 ScrollView ,其上有 Collection View 和 Collection View 单元格。我的收藏 View 单元格包含图像和标签我想在 Collection View 单元格的不同行中显示不同的图像。但我在表格 View 单元格的每个部分都得到相同的图像。请帮助我。

最佳答案

UICollectionView 继承自 UIScrollView,这意味着如果我正确理解您的结构,您不需要在 ScrollView 中拥有 UICollectionView。一旦图像/内容超出 View 框架, Collection View 就会滚动。 UITableViews 也继承自 UIScrollView,因此它也已经具有在内容大小超过 TableView 框架时滚动的功能。

在每个 TableView 单元格中都有一个 Collection View 可能不是实现您需要/想要的最佳方式。然而,问题似乎是您为每个 Collection View 分配相同的数据源,但没有看到任何代码,我不得不猜测您正在创建一个 Collection View ,为其分配数据,然后将其添加到每个 TableView 单元格。

关于swift - 如何在单个 TableViewcell 的不同部分拥有不同的图像,并将 Collection View 放置在 tableviewCell 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52293287/

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