1
我具有以下和鳥類的字符串數組和圖像kindsViewController.swift
顯示圖像中選擇
如何顯示動物的所有的圖像,如果「任何」是從動物陣列選擇的圖像,如果「任何」從鳥陣列集合視圖中選擇
這是我迄今所做
class kindsViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var titleDisplayed: UINavigationItem!
var kind = [String]()
var kindImages = [UIImage]()
let animals = ["Dog","Cat","Rabbit", "Any"]
let birds = ["Hen","Kiwi","Parrot", "Any"]
let animalImages: [UIImage] = [UIImage(named: "imageDog")!, UIImage(named: "imageCat")!,UIImage(named: "imageRabbit")!]
let birdImages: [UIImage] = [UIImage(named: "imageHen")!,UIImage(named: "imageKiwi")!,UIImage(named: "imageParrot")!]
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showOptions"
{
let indexPaths = self.collectionView!.indexPathsForSelectedItems!
let indexPath = indexPaths[0] as IndexPath
let AVC = segue.destination as! DisplayViewController
AVC.labelSelected = self.kind [(indexPath as NSIndexPath).row]
// AVC.imageSelected = animalImages
}
}
以下是DisplayViewController.swift
class DisplayViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource{
var labelSelected = String()
var imageSelected = [UIImage]()
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
as! DisplayCollectionViewCell
cell.imageView?.image = imageSelected[(indexPath as NSIndexPath).row]
return cell
}