Ios 集合视图单元格中的图像
我正在集合视图中显示来自解析后端的图像 在CollectionViewController中,我有以下工作代码:Ios 集合视图单元格中的图像,ios,swift,Ios,Swift,我正在集合视图中显示来自解析后端的图像 在CollectionViewController中,我有以下工作代码: class CollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { @IBOutlet var collection: UICollectionView! override func viewDidL
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 {
}
通常我会在单元格内的imageview中添加一个插座
该错误在此代码处提供了一个断点
let cell:CellCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
作为CellCollectionViewCell
let cell:CellCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(**reuseIdentifier**, forIndexPath: indexPath)
它应该是一个字符串,您必须在情节提要中设置此标识符。您是否已正确注册了
CellCollectionViewCell
类以供重用?