问题是,当我启动我的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