ios – 集合视图单元格在swift中慢速检测所选项目

ios – 集合视图单元格在swift中慢速检测所选项目,第1张

概述我将集合视图放入表格视图单元格,我使它可以显示在单元格上,但是当我想选择集合单元格(更改颜色或打印单元格编号)时,选择功能不起作用,我需要多次点击该单元格以使其被选中.为什么单元格慢速检测所选项目?什么代码会影响要选择的单元格? 这是选择集合单元格的代码 override func awakeFromNib() { super.awakeFromNib() let layout: 我将集合视图放入表格视图单元格,我使它可以显示在单元格上,但是当我想选择集合单元格(更改颜色或打印单元格编号)时,选择功能不起作用,我需要多次点击该单元格以使其被选中.为什么单元格慢速检测所选项目?什么代码会影响要选择的单元格?

这是选择集合单元格的代码

overrIDe func awakeFromNib() {    super.awakeFromNib()    let layout: UICollectionVIEwFlowLayout = UICollectionVIEwFlowLayout()    let wIDth = UIScreen.main.bounds.wIDth    layout.scrollDirection = .vertical    layout.sectionInset = UIEdgeInsets(top: 0,left: 0,bottom: 0,right: 0)    layout.itemSize = CGSize(wIDth: wIDth/5,height: wIDth/4)    layout.minimumInteritemSpacing = 0    layout.minimumlinespacing = 0    collectionVIEw?.collectionVIEwLayout = layout    collectionVIEw?.delaysContenttouches = false}func collectionVIEw(_ collectionVIEw: UICollectionVIEw,cellForItemAt indexPath: IndexPath) -> UICollectionVIEwCell {    let cell = collectionVIEw.dequeueReusableCell(withReuseIDentifIEr: "CollectionVIEwCell",for: indexPath) as! categoryCollectionVIEwCell    cell.cateimg.image = imagename[indexPath.row]    cell.cateLabel.text! = nameArray[indexPath.row]    return cell}func collectionVIEw(_ collectionVIEw: UICollectionVIEw,dIDSelectItemAt indexPath: IndexPath) {    if let cell = collectionVIEw.cellForItem(at: indexPath) as? categoryCollectionVIEwCell {        cell.cateimg.image = imagename2[indexPath.row]        print("collectionVIEwCell selected \(indexPath)")    }}func collectionVIEw(_ collectionVIEw: UICollectionVIEw,dIDdeselectItemAt indexPath: IndexPath) {    if let cell = collectionVIEw.cellForItem(at: indexPath) as? categoryCollectionVIEwCell {        cell.cateimg.image = imagename[indexPath.row]    }}

项目拉链:
https://www.dropbox.com/s/y10dgp3q61pi5n1/Finnciti.zip?dl=0

AddVIEwCell.swift上的问题

解决方法 我在AddVIEwController上删除此代码后修复了问题.

let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self,action: #selector(AddExpenseVC.dismissKeyboard))vIEw.addGestureRecognizer(tap)@objc func dismissKeyboard() {    vIEw.endEditing(true)}
总结

以上是内存溢出为你收集整理的ios – 集合视图单元格在swift中慢速检测所选项目全部内容,希望文章能够帮你解决ios – 集合视图单元格在swift中慢速检测所选项目所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1008470.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存