gpt4 book ai didi

ios - 将图像数组发送到新的 View Controller

转载 作者:行者123 更新时间:2023-11-28 14:13:08 25 4
gpt4 key购买 nike

我目前有一个 Tableview,当用户点击时,会将它们发送到一个显示一张图片的新 View Controller 。但是,因为我需要它们能够滑动以显示与第一张图片相关联的第二张图片(取决于选择的行),所以我正在尝试创建一个要发送的数组。我(认为?)已经成功创建了一个数组,但我遇到了代码问题,因为它无法正确“发送”。我想知道我哪里错了,我需要做哪些更改才能发送数组,以便用户可以滑动并查看第二张图片。如果您需要更多代码,请告诉我,我将在其中对其进行编辑。谢谢!

let firstchoice: [UIImage] = [
UIImage(named: "Appa1")!,
UIImage(named: "Appa2")!
]


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
///Right way here
///You can easily manage using this
let Vc = self.storyboard?.instantiateViewController(withIdentifier: "imageViewController") as! imageViewController



///Here you have written four Animal names in Array
///So There is going to four case 0,1,2,3 and a default case
switch indexPath.row
{
case 0:
Vc.passedImage = UIImage.init(named: firstchoice)
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 1:
Vc.passedImage = UIImage.init(named: "AppA2")!
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 2:
Vc.passedImage = UIImage.init(named: "AppB")!
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 3:
Vc.passedImage = UIImage.init(named: "AppC")!
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 4:
Vc.passedImage = UIImage.init(named: "AppD")!
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 5:
Vc.passedImage = UIImage.init(named: "AppE")!
self.navigationController?.pushViewController(Vc, animated: true)
break;

ImageView Controller :

import UIKit
import GoogleMobileAds


class imageViewController: UIViewController,GADBannerViewDelegate, UIGestureRecognizerDelegate, UIScrollViewDelegate {

var bannerView: GADBannerView!

@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var myImageView: UIImageView!


//var passedImage : UIImage! = nil
var passedImage : [UIImage]


override func viewDidLoad(){
super.viewDidLoad()
self.myImageView.image = passedImage
self.navigationController?.navigationBar.isHidden = false

scrollView.minimumZoomScale = 1.0
scrollView.maximumZoomScale = 5.0

最佳答案

您的 passedImage 似乎是 imageViewController 中的一个 UIImage 变量。您需要做的是将其更改为 [UIImage]。这将使您可以存储一组图像。

之后你切换会是这样的。

switch indexPath.row {
case 0:
Vc.passedImage = firstchoice
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 1:
Vc.passedImage = [UIImage.init(named: "AppA2")!]
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 2:
// Rest of your cases follow suit.
}

您需要使用相应的索引从图像数组中访问图像。

旁注:使用 lowerCamelCase 作为变量名,就像他们在 Swift naming conventions 中所说的那样.

关于ios - 将图像数组发送到新的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52372986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com