最新消息:VPS服务器又从fzhost.net换回Linode了,主题仍用朋友推荐的大前端D8

【已解决】swift初始化collectionView=UICollectionView()出错:UICollectionView must be initialized with a non-nil layout parameter

Swift crifan 132浏览 0评论

代码:

self.collectionView = UICollectionView()

出错:

2015-12-11 20:09:40.730 JianDao[4409:186125] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘UICollectionView must be initialized with a non-nil layout parameter’

搜:

UICollectionView must be initialized with a non-nil layout parameter

参考:

iOS 开发中常见的错误及解决方法 – 简书

ios – UICollectionView: must be initialized with a non-nil layout parameter – Stack Overflow

后来改为:

import UIKit

class PersonInfoViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
   
let totalItemNumInRow:Int = 5
   
   
var memberList:[ContactItem]
   
let curPersonContactItem:ContactItem
   
   
let flowLayout:UICollectionViewFlowLayout

    let collectionView:UICollectionView
   
   
init(personContactItem:ContactItem) {
       
self.curPersonContactItem = personContactItem
       
self.memberList = [ContactItem]()
       
       
self.flowLayout = UICollectionViewFlowLayout()
       
self.flowLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal
       
self.flowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20)
       
self.flowLayout.itemSize = CGSizeMake(41, 41)

        self.collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: flowLayout)

        
        super.init(nibName: nil, bundle: nil)
    }

}

即可。

转载请注明:在路上 » 【已解决】swift初始化collectionView=UICollectionView()出错:UICollectionView must be initialized with a non-nil layout parameter

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
20 queries in 0.241 seconds, using 9.87MB memory