ios - 集合视图未显示在 UITableViewController 中
问题描述
我想在 UITableViewController 类中显示 UICollectionView。我已经看过该工作的视频和代码,但显然它不再在 Swift 5 中工作,或者至少我不知道如何在 Swift 5 中设置它。我以编程方式完成所有事情。这是我在 viewDidLoad() 中调用的函数,但它似乎不起作用:
func configureCollectionView() {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
let frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height - (tabBarController?.tabBar.frame.height)! - (navigationController?.navigationBar.frame.height)!)
collectionView = UICollectionView(frame: frame, collectionViewLayout: layout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.alwaysBounceVertical = true
collectionView.backgroundColor = .white
collectionView.register(SearchCell.self, forCellWithReuseIdentifier: "SearchCell")
tableView.addSubview(collectionView)
tableView.separatorColor = .clear
}
我还调用了这些 collectionView 函数:
minimumInteritemSpacingForSectionAt
minimumLineSpacingForSectionAt
sizeForItemAt
numberOfItemsInSection
cellForItemAt
didSelectItemAt
我能做些什么来解决我的问题?
解决方案
设置成这样
collectionView.backgroundColor = .black
,你能看到black
背景吗?
推荐阅读
- ios - iOS 的 Ionic 构建失败
- python-3.x - 如何使用 sympy 的线性方程求解器创建的解决方案
- css - 将文本设置在左侧,而其他元素居中 - CSS - Bootstrap 4
- java - 无法使用来自用户的对话和 DialogFlow(api.ai) 填充我的 RecyclerView
- python - 将具有多种状态的 QtQuick 项目保存到 .png 文件
- c++ - LNK2019:OpenCV 中未解析的外部符号
- java - 用 oscP5 处理到蚂蚱
- javascript - Rxjs 与 Lodash 对比?rxjs 可以替代 lodash 吗?
- javascript - onClick 在第一次单击时不起作用
- windows - 通过 WSL 修改 Windows 只读文件的访问时间