override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as? PictureCellForHomeVC {
picArray[indexPath.row].getDataInBackgroundWithBlock({ (data: NSData?, error: NSError?) in
if error == nil {
if let data = data {
let image = UIImage(data: data)
cell.imageView.image = image
return cell
}
}
})
}else {
return UICollectionViewCell()
}
}
に予期しない非ボイド戻り値Iは、エラーが表示されます。上記のコードでCollectionView cellForItemAtIndexPath DataSourceメソッド
Unexpected Non Void return value in void function
私の上記のコードでpicArray
は、私が呼び出すことができますPFFile
オブジェクトとのコードですgetDataInBackgroundWithBlock
メソッド。
getDataInBackgroundWithBlock
のcompletionHandlerがvoid
を返すので、私はエラーが何を意味するのか理解しています。私はこのセルを返すことはできませんが、この問題を解決する方法に固執しています。
私はメソッドを呼び出さないため、データソースメソッドなので、メソッドcellForItemAtIndexPath
に別のクロージャを渡すことさえできません。誰も私はこの問題を解決する方法を知っていますか?
をブロックコードの後に復帰 'cell'を行います(これは非同期でなければなりません)、 '})'の後ろ、 '} else'の前です。イメージが見つからなくても、セルを返さなければなりません。 – Larme
@Larmeしたがって、 'else 'の前に' return cell'を置くと、 'cellForItemAtIndexPath'が' getDataInBackgroundWithBlock'へのコールバックを返してもイメージが正しく更新されます。 – CapturedTree