【发布时间】:2018-09-12 10:44:36
【问题描述】:
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
}
我有一个表格视图,因为我有一个表格视图单元格。 我有不同部分的表格视图单元格。 在那个单元格中有一个滚动视图,上面有集合视图和集合视图单元格。 我的收藏视图单元格包含一个图像和一个标签 我想在集合视图单元格的不同行中显示不同的图像。但是我在表格视图单元格的每个部分都得到相同的图像。请帮助我。
【问题讨论】:
-
没有代码,很难说。您是否在 UITableViewCell 中重新加载了 collectionView?是重用问题吗?
-
如果你能显示你的代码就做
-
您可能需要以更好的方式处理数据源
-
我已经上传了代码。现在你能帮我吗
标签: swift uitableview uicollectionview uicollectionviewcell