2017-03-03 29 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] 
相關問題