2017-03-03 28 views
1

我试图将图像文字添加到数组,并按照索引显示它们。如何将图像文字添加到数组并显示它们?

这里是我的代码:

var images = [#imageLiteral(resourceName: "male-circle-128"),#imageLiteral(resourceName: "add_to_favourite-128"),#imageLiteral(resourceName: "28468-200"),#imageLiteral(resourceName: "progress_circular"),#imageLiteral(resourceName: "logout-1-128")] 

和展示这样

cell!.imageView?.image = UIImage.init(cgImage: images[indexPath.row] as! CGImage)

了EXC_BAD_INSTRUCTION!什么是做这个

enter image description here

+0

不要理解为什么你会因数组声明而崩溃,因为它对我来说是完美的。 –

+0

@EricAya no UIImage only –

+0

当我将这些元素添加到数组时,会崩溃。 –

回答

0

让图像的正确方法:[UIImage的] = [图像文字的阵列放在这里]

0

你为什么投给CGImage,您的文字是UIImage,你可以使用它们而不需要投射,即使你想CGImage使用初始化工具也不投射。

let images = [literal images are here] 
    imageview.image = images[indexPath.row] 
相关问题