代码:
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 – UICollectionView: must be initialized with a non-nil layout parameter – Stack Overflow
后来改为:
import UIKitclass 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