Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 数组中的字典,字符串为键,图像为值_Arrays_Swift - Fatal编程技术网

Arrays 数组中的字典,字符串为键,图像为值

Arrays 数组中的字典,字符串为键,图像为值,arrays,swift,Arrays,Swift,我声明了一个名为imagearray1的数组。每个索引都有字典值。我已经创建了一个imageview。如何将图像指定给该imageview? 如何用字典值打破数组?正如大家所说的imageArray1不是数组,而是字典 要获取图像并放入UIImageView,可以执行以下操作: var imagearray1 = ["AvengerPic1": UIImage(named: "AvengerPic1")!, "AvengerPic2": UIImage(named: "AvengerPic2")

我声明了一个名为imagearray1的数组。每个索引都有字典值。我已经创建了一个imageview。如何将图像指定给该imageview?
如何用字典值打破数组?

正如大家所说的
imageArray1
不是数组,而是字典

要获取图像并放入UIImageView,可以执行以下操作:

var imagearray1 = ["AvengerPic1": UIImage(named: "AvengerPic1")!, "AvengerPic2": UIImage(named: "AvengerPic2")!, "AvengerPic3": UIImage(named: "AvengerPic3")!, "AvengerPic4": UIImage(named: "AvengerPic4")! ]
//1。从字典中提取所有图像值
让images=imagearray1.map{$0.1}
//2. 循环浏览图像并在ImageView中设置
对于0..
imagearray1
是一个字典,而不是数组。通过key.var imagearray1:[“字符串”:uiimage]=[“AvengerPic1”:uiimage(命名为:“AvengerPic1”)!,“AvengerPic2”:uiimage(命名为:“AvengerPic2”)!,“AvengerPic3”:uiimage(命名为:“AvengerPic3”),“AvengerPic4”:uiimage(命名为:“AvengerPic4”)!]获取值。很抱歉没有写信。如何从数组中获取图像。无论如何,是字典@VirenPatel它是一个带有key:String和value作为UIImage的字典一个带有字典值的数组是这样声明的
var-imagearray1:[[String:UIImage]]
谢谢。这真的会有帮助
    //1. Extract All The Image Values From The Dictionary
    let images = imagearray1.map { $0.1 }

    //2. Loop Through The Images & Set In ImageViews
    for index in 0 ..< images.count{

        let imageHolder = UIImageView(frame: CGRect(x: 0, y: 110 * index, width: 100, height: 100))
        self.view.addSubview(imageHolder)
        imageHolder.image = images[index]
    }