【发布时间】:2021-10-03 17:00:39
【问题描述】:
我想在 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
我可以做些什么来解决我的问题?
【问题讨论】:
标签: ios swift uitableview uicollectionview swift5