ios - CollectionView 委托方法未从 TableViewCell 调用
问题描述
没有从 tableViewCell 调用委托。这是UICollectionViewDelegate
和UICollectionViewDataSource
代码
extension HomeVC:UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProductCell", for: indexPath)
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("ok")
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let lay = collectionViewLayout as! UICollectionViewFlowLayout
lay.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
lay.minimumInteritemSpacing = 0
lay.minimumLineSpacing = 0
collectionView.collectionViewLayout = lay
let size = (collectionView.frame.size.width-10) / 2
return CGSize(width: size, height: size)
}
}
解决方案
每次在 Tableview 委托 CellForRowAtIndexPath 中,您都需要为 collectionView 设置数据源和委托。
推荐阅读
- php - $this->__construct() 在父类中调用子类的构造?
- asp.net - 如何使用 Sql 数据适配器在 ASP.NET MVC 中进行分页
- c++ - 错误表达式必须有指向对象类型的指针
- vue.js - 无法在'Storage'上执行'setItem':设置'136114546'的值超出了配额Vue
- list - 在 Prolog 列表中的每个元素之后插入元素
- macos - Mac系统上的“zsh:找不到命令:mvn” intellij ver 2020.2社区
- python - JSON 解码器错误 - 需要 ',' 分隔符:第 1 行第 22 列(字符 21)
- spring-boot - 使用 Spring BOOT 创建访问网页的角色要求
- java - 如何制作总和为 n(n-1)/2 的数字列表
- visual-studio-code - VSCode对vim的ci的快捷命令是什么
VSCode 有办法在标签之间进行选择吗?而且我的意思不仅仅是折叠和取消折叠,我的意思是选择开始标签和结束标签之间的所有内容。