cellForItemAt如果我正在使用UICollectionViewDelegateFlowLayout,则不会调用IndexPath.这是iOS的错误吗?

cellForItemAt如果我正在使用UICollectionViewDelegateFlowLayout,则不会调用IndexPath.这是iOS的错误吗?,第1张

概述cellForItemAt如果我正在使用UICollectionViewDelegateFlowLayout,则不会调用indexPath. 在这种情况下: class Something: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {} 它调用我的cellforItemAtIndexPath, cellForItemAt如果我正在使用UICollectionVIEwDelegateFlowLayout,则不会调用indexPath.

在这种情况下:

class Something: UIVIEwController,UICollectionVIEwDelegate,UICollectionVIEwDataSource {}

它调用我的cellforItemAtIndexPath,但不调用我的

func collectionVIEw(_ collectionVIEw: UICollectionVIEw,layout collectionVIEwLayout: UICollectionVIEwLayout,sizeforItemAt indexPath: IndexPath) -> CGSize {}

但如果我包含UICollectionVIEwDelegateFlowLayout:

class Something: UIVIEwController,UICollectionVIEwDataSource,UICollectionVIEwDelegateFlowLayout {}

它会打电话给:

func collectionVIEw(_ collectionVIEw: UICollectionVIEw,sizeforItemAt indexPath: IndexPath) -> CGSize {}

但不会调用cellForItemAtIndexPath.我不明白这个问题.这是iOS的错误还是我看不到任何东西?

解决方法 试试这个代码.

import UIKitlet kSCREENWIDTH = UIScreen.main.bounds.size.wIDthlet kSCREENHEIGHT = UIScreen.main.bounds.size.heightlet ColLECTION_CELL = "collectionCell"class DemoController: UIVIEwController {    var collectionVIEw : UICollectionVIEw!    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        setupCollectionVIEw()    }   /// create programatically collection vIEw   fileprivate func setupCollectionVIEw() {        let layout = UICollectionVIEwFlowLayout()//        layout.itemSize = CGSize(wIDth:(kSCREENWIDTH-20)/2,height:150)        layout.sectionInset = UIEdgeInsetsMake(5,7,5,7)        layout.minimumlinespacing = 5        layout.minimumInteritemSpacing = 1        collectionVIEw = UICollectionVIEw.init(frame: self.vIEw.bounds,collectionVIEwLayout: layout)        collectionVIEw.delegate = self        collectionVIEw.dataSource = self        collectionVIEw.backgroundcolor = UIcolor.white        self.vIEw .addSubvIEw(collectionVIEw)        collectionVIEw.register(UICollectionVIEwCell.self,forCellWithReuseIDentifIEr: ColLECTION_CELL)    }    overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()        // dispose of any resources that can be recreated.    }}//MARK: UICollectionVIEwDelegateextension DemoController : UICollectionVIEwDelegate {    func collectionVIEw(_ collectionVIEw: UICollectionVIEw,numberOfItemsInSection section: Int) -> Int {        return 10    }    func collectionVIEw(_ collectionVIEw: UICollectionVIEw,dIDSelectItemAt indexPath: IndexPath) {            // add your code here    }}//MARK: UICollectionVIEwDataSourceextension DemoController : UICollectionVIEwDataSource {    func collectionVIEw(_ collectionVIEw: UICollectionVIEw,cellForItemAt indexPath: IndexPath) -> UICollectionVIEwCell {        /// add your code here        let cell = collectionVIEw.dequeueReusableCell(withReuseIDentifIEr: ColLECTION_CELL,for: indexPath)        cell.backgroundcolor = UIcolor.lightGray        print("Here cellForItemAt Works")        return cell    }}//MARK: UICollectionVIEwDelegateFlowLayoutextension DemoController : UICollectionVIEwDelegateFlowLayout {    func collectionVIEw(_ collectionVIEw: UICollectionVIEw,sizeforItemAt indexPath: IndexPath) -> CGSize {        print("Here sizeforItemAt Works")        return CGSize(wIDth: 150,height: 150)    }}
总结

以上是内存溢出为你收集整理的cellForItemAt如果我正在使用UICollectionViewDelegateFlowLayout,则不会调用IndexPath.这是iOS的错误吗?全部内容,希望文章能够帮你解决cellForItemAt如果我正在使用UICollectionViewDelegateFlowLayout,则不会调用IndexPath.这是iOS的错误吗?所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1031943.html

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

发表评论

登录后才能评论

评论列表(0条)

保存