override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = self.collectionView?.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! PictureCell
picArray[indexPath.row].getDataInBackground{(data:Data?, error:Error?) in
if error == nil{
cell.*picImg*.image = UIImage(data: data!)
}else{
print(error?.localizedDescription as Any)
}
}
return cell
}
The above part funs well, and then...
override func awakeFromNib() {
super.awakeFromNib()
let width = UIScreen.main.bounds.width
// I got an error in the following line:
picImg.frame = CGRect(x:0, y:0, width: width/3, height: width/3)
}
I got an error in the above mentioned line: " use of unresolved identifier 'picImg'. I declared " picImg " in another Cocoa Touch Class of this project. The code is as following:
import UIKit
class PictureCell: UICollectionViewCell {
@IBOutlet weak var picImg: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
let width = UIScreen.main.bounds.width
picImg.frame = CGRect(x:0, y:0, width: width/3, height: width/3)
}
}
The question is why Xcode didn't report error at the first time I used " picImg " (in collectionView function) but report error in the other. How could I solve this problem ? Thanks for your help.