Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将UITableViewCell用作HeaderView时不显示集合视图_Ios_Swift_Uitableview_Uicollectionview_Uitableviewsectionheader - Fatal编程技术网

Ios 将UITableViewCell用作HeaderView时不显示集合视图

Ios 将UITableViewCell用作HeaderView时不显示集合视图,ios,swift,uitableview,uicollectionview,uitableviewsectionheader,Ios,Swift,Uitableview,Uicollectionview,Uitableviewsectionheader,我正在尝试将集合视图嵌入自定义UITableViewCell中,该自定义UITableViewCell用作每个表视图单元格的HeaderView。这是我在故事板中使用的层次结构 这是自定义标题表视图单元格的代码。集合视图从情节提要连接到类,我正在表视图单元格中设置委托和数据源,并且我正在实现CollectionView数据源中所需的所有协议。出于测试目的,我简单地将项目数硬编码为10,单元格应该只显示一个标签,文本为“test”,背景颜色为红色 var headerDelegate:Heade

我正在尝试将集合视图嵌入自定义UITableViewCell中,该自定义UITableViewCell用作每个表视图单元格的HeaderView。这是我在故事板中使用的层次结构

这是自定义标题表视图单元格的代码。集合视图从情节提要连接到类,我正在表视图单元格中设置委托和数据源,并且我正在实现CollectionView数据源中所需的所有协议。出于测试目的,我简单地将项目数硬编码为10,单元格应该只显示一个标签,文本为“test”,背景颜色为红色

var headerDelegate:HeaderTableViewCellDelegate?

var timeInterval:TimeInterval?

@IBOutlet private weak var collectionView: UICollectionView!

var exercise:ExerciseRealm!

var workout:Workout!

@IBOutlet weak var collectionLayout: UICollectionViewFlowLayout! {
    didSet {
        collectionLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
    }
}

@IBOutlet weak var exerciseNameLabel: UILabel!
override func awakeFromNib() {
    super.awakeFromNib()
    self.collectionView.delegate = self
    self.collectionView.dataSource = self
    //TODO: need to setup collection view flow layout
     let flowLayout = UICollectionViewFlowLayout()
     flowLayout.scrollDirection = .horizontal
     flowLayout.itemSize = CGSize(width: 70, height: 80)
     flowLayout.minimumLineSpacing = 5.0
     flowLayout.minimumInteritemSpacing = 5.0
     self.collectionView.collectionViewLayout = flowLayout


}

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

func numberOfSections(in collectionView: UICollectionView) -> Int {

    return 1
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewID", for: indexPath) as! HeaderCollectionViewCells

    cell.updateCellWithIndicator(indicator: "test")
    cell.backgroundColor = .red

    return cell
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
    return UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
}
在我的主TableViewController中,我使用以下代码将此单元格显示为标题视图

    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell") as! HeaderTableViewCell

    guard let workout = workout else {print("workout is nil in viewForHeaderInSection");return cell}

    let exercises = workout.exercisesList

    cell.headerDelegate = self
    cell.exercise = exercises[section]
    cell.workout = workout

    return cell


}

虽然我已经从序列图像板和代码中将数据源和委托从集合视图设置为自定义标题表视图单元格,但集合视图仍然没有显示。header视图中的每一个其他数据都按照它应该的样子显示,所以我真的不知道在实现collection视图时缺少了什么

collectionView中的
numberOfItemsInSection
是否至少调用或未调用任何
collectionView
方法?提供问题的详细信息。collectionView中的
numberOfItemsInSection
是否至少调用或未调用任何
collectionView
方法?提供问题的详细信息。