問題是,當我啓動我的iOS應用程序集合視圖顯示,但沒有顯示任何圖像。我在Info.plist下添加了一個文件夾,其中我的圖片被命名爲1.jpg和2.jpg。我的UICollectionView沒有顯示圖像
let array:[String] = ["1","2"]
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return array.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! myCell
cell.imag.image = UIImage(named: array[indexPath.row] + ".jpg")
return cell
}
你需要調試:'的UIImage(命名爲:數組[indexPath.row] + 「.JPG」 )'是零?您應該使用'UIImage(named:array [indexPath.row])'代替。此外,「cell.imag」的框架是什麼? – Larme