I've collection view and cell configured from array, I want to set the image of cell's UIImageView from the array, but xCode returns an error saying: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value, I don't know if it's helpful, but I can't even open the tab where collectionView and its cell is located, the app crashes immediately
//collectionViewCell
@IBOutlet weak var headerTitle: UILabel!
@IBOutlet weak var infoLabel: UILabel!
@IBOutlet weak var countryImage: UIImageView!
func config(data:SearchCollectionViewData){
self.headerTitle.text = data.header
self.infoLabel.text = data.information
self.countryImage.image = data.image // error goes here
}
//collectionView and its configuration
var array2:[SearchCollectionViewData] = [
SearchCollectionViewData(header: "Georgia,Tbilisi Airport", information: "Georgia is located between Asia and Europe and occupies a land area of 69,700 square kilometres, bordered by the Black Sea to the west, Turkey to the southwest, Azerbaijan to the east, Russia to the north, and Armenia to the south. ... Georgian is the official language of Georgia, and it is spoken by 71% of the population.", image: UIImage(named: "tbtbtb")!)
]
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "searchCell", for: indexPath) as! searchCollectionViewCell
cell.config(data: array2[indexPath.row])
}
!in code: one of your outlets might not be hooked up properly, your image name might be incorrect, the dequeued cell type might not be what you expect.UIImage(named: "tbtbtb")?@IBOutlet weak var headerTitle: UILabel!line incollectionViewCell