-2
我正在顯示來自集合視圖中的分析後端的圖像。收集視圖的單元格中的圖像
在CollectionViewController我有這方面的工作代碼:
class CollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
@IBOutlet var collection: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Register cell classes
self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
//#warning Incomplete method implementation -- Return the number of sections
println(numberOfDistinctValueInTypeOfStore)
return numberOfDistinctValueInTypeOfStore
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//#warning Incomplete method implementation -- Return the number of items in the section
return 1
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell:UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell
// Configure the cell
cell.backgroundColor = UIColor.redColor()
return cell
}
我想圖像添加到單元格。 所以我的方法來改變這一點,應用程序崩潰:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell:UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell
// Configure the cell
cell.backgroundColor = UIColor.redColor()
return cell
}
而且,即使CellCollectionViewCell是空的這個樣子。它會崩潰沒有錯誤信息
class CellCollectionViewCell: UICollectionViewCell {
}
通常我會添加一個插座到單元格內的圖像視圖。
錯誤在此代碼
let cell:CellCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
給出了一個斷點爲CellCollectionViewCell
你有沒有正確地註冊你的'CellCollectionViewCell'類來重用? – spassas