Please tell me how to set up a two-dimensional array of images.

Asked 2 years ago, Updated 2 years ago, 34 views

I put UIImage in ViewdidLoad by creating an array like the one below. How can I write it when I program it in a two-dimensional array?

@IBOutlet varmainImage:UIImageView!
variableListArray:Array<UIImage>=[ ]
var number : Int!// Number // Respondent modification delivered from previous page

override func viewDidLoad(){
    super.viewDidLoad()

    // UIImage
    let image0:UIImage!=UIImage(named: "img.png")
    let image1: UIImage!= UIImage(named: "img.png") // Provisional

    // ImageListArray
    imageListArray.append(image0)
    imageListArray.append(image1)

    mainimage.image=imageListArray [number]
}

ios swift

2022-09-30 18:39

1 Answers

Swift does not have a special array called a two-dimensional array, but it achieves something similar in the form of an array.

varimageListArray:Array<UIImage>=[]

If you arrange this in two dimensions,

varimageListArray:Array<Array<UIImage>>=[UIImage]]()

Also, as Swift's syntax sugar, the array type can be described as [UIImage], so

varimageListArray: [[UIImage]]=[UIImage]]()

You can write it like this.

Accessing elements of an array is required by

imageListArray[2][3]

This is what happens.Same as C.


2022-09-30 18:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.