gpt4 book ai didi

ios - 如何将 tableView 放在节标题中

转载 作者:行者123 更新时间:2023-11-28 06:16:54 25 4
gpt4 key购买 nike

我正在尝试将 tableView 放入 collectionView sectionHeader 中。我尝试在 Storyboard的标题中添加一个 tableView,然后将其类设置为 tableViewController.swift,但这没有用。(我用的是swift)

最佳答案

经过一些尝试,我确实设法让它正常工作。首先我像往常一样创建了一个标题,然后创建了 tableView 的 IBOutlet。然后我简单地设置头文件,就像设置 tableViewController 一样,连接到数据源并在 awakeFromNib 中委托(delegate)并完成。

class HomeHeader: UICollectionReusableView, UITableViewDataSource, UITableViewDelegate {


@IBOutlet weak var tableView: UITableView!


override func awakeFromNib() {

tableView.delegate = self
tableView.dataSource = self
//tableView.backgroundColor = UIColor.clear
}

func numberOfSections(in tableView: UITableView) -> Int {

return 1 //number of sections
}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {


return 5 //number of cells
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
cell.textLabel?.text = "test"
// cell.backgroundColor = UIColor.clear

return cell
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


}



}

关于ios - 如何将 tableView 放在节标题中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44859007/

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