在这种情况下:
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的错误吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)