将CollectionView添加为表视图标题

时间:2017-01-13 09:38:45

标签: ios swift uitableview uicollectionview

我想要展示这样的横幅:

enter image description here

我的方法是将o2 = do.call(grouping, df) ends = attr(o2, "ends") gr2 = rep(seq_along(ends), c(ends[1], diff(ends)))[order(o2)] gr2 #[1] 3 4 1 2 3 1 LETTERS[match(gr2, unique(gr2))] #[1] "A" "B" "C" "D" "A" "C" 添加为CollectionView

我的代码:

TableViewHeader

我的extension HomeViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { func configureHeaderView() { let layout = UICollectionViewFlowLayout() layout.scrollDirection = .horizontal layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) let headerView = UICollectionView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: headerHeight), collectionViewLayout: layout) headerView.backgroundColor = .blue headerView.isPagingEnabled = true headerView.isUserInteractionEnabled = true headerView.dataSource = self headerView.delegate = self headerView.register(BannerCollectionViewCell.self, forCellWithReuseIdentifier: BannerCollectionViewCell.reuseIdentifier) headerView.showsHorizontalScrollIndicator = false tableView.tableHeaderView = headerView } // MARK: UICollectionViewDataSource func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 3 } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: BannerCollectionViewCell.reuseIdentifier, for: indexPath) as! BannerCollectionViewCell return cell } // MARK: UICollectionViewDelegateFlowLayout func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: UIScreen.main.bounds.width, height: headerHeight) } } 有一张默认图片。

BannerCollectionViewCell

enter image description here

但我在标题上看不到那个图像。它只显示一个空标题。

2 个答案:

答案 0 :(得分:5)

您使用 NIB ,因此您应该使用func register(UINib?, forCellWithReuseIdentifier: String)代替func register(AnyClass?, forCellWithReuseIdentifier: String)

答案 1 :(得分:-1)

也许您正在寻找顶部而非集合视图的KIImagePager图像寻呼机。您也可以使用内置的PageViewController创建相同的内容。

您可以在此下单独添加TableView

相关问题