CollectionViewController
import UIKit
private let reuseIdentifier = "cell"
class ControllerListCollectionView: UICollectionViewController, UICollectionViewDelegateFlowLayout {
private var selectedZone: ZoneListBrain.zone?
private var controllerKeys: [String]?
override func viewDidLoad() {
super.viewDidLoad()
let aFlowLayout = UICollectionViewFlowLayout()
aFlowLayout.itemSize = CGSizeMake(100, 22)
self.collectionView!.collectionViewLayout = aFlowLayout
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { if selectedZone?.controller != nil {
return (selectedZone?.controller?.count)!
} else {
return 0//초기값
}
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! ControllerListCell
cell.backgroundColor = UIColor.redColor()
if controllerKeys != nil {
cell.listLabel.text = controllerKeys![indexPath.item]
cell.listLabel.textAlignment = NSTextAlignment.Center
return cell
}
return cell
}
func GetZoneControllerList(select: ZoneListBrain.zone) {
selectedZone = select
controllerKeys = [String](selectedZone!.controller!.keys)
self.collectionView?.reloadData()//오류 발생지점!
}
}
오류내용
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'
질문입니다. collectionView?.reloadData() 만 사용을 하면 위와같은 오류가 발생합니다. 저는 위와같은 오류로 2주일 가까이 고민하고 있지만 해결을 못하고 있습니다.... 꼭 해결하고 싶습니다. 그리고 collectionView 라고 하는것은 어디에 있는것인가요? 어디에 있는것이길래 이렇게 불러와서 사용을 하는것인지도 궁금합니다.