Iam使用表格视图内部的集合视图构建iOS应用程序.Iam每行具有三行,其内部具有集合视图.Iam计划每行每个部分具有三个部分。例如,第一行应该在单独的部分中,标题与第二行和第三行的相似之处。 每当我创建三个部分时,我都会获取所有三个部分中的所有三行。我希望每个行都有一个单独的带有标题的部分。
import UIKit
class StoreVC: UIViewController,UITableViewDelegate,UITableViewDataSource {
@IBOutlet weak var CoursetableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
CoursetableView.tableFooterView = UIView()
CoursetableView.delegate = self
CoursetableView.dataSource = self
}
func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
func tableView(_ tableView: UITableView,titleForHeaderInSection section: Int) -> String? {
if section == 0
{
return "Courses"
}
else if section == 1
{
return "Tests"
}
return "Bundles"
}
func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath) as! CourseRow
return cell
}
else if indexPath.row == 1
{
let cell = tableView.dequeueReusableCell(withIdentifier: "testcell",for: indexPath) as! TestRow
return cell
}
else if indexPath.row == 2
{
let cell = tableView.dequeueReusableCell(withIdentifier: "bundlecell",for: indexPath) as! BundleRow
return cell
}
return UITableViewCell()
}
}