gpt4 book ai didi

image - 在 uicollectionview 上快速将图像传递给详细 View Controller

转载 作者:行者123 更新时间:2023-11-28 06:57:41 25 4
gpt4 key购买 nike

我已经有一段时间了,但似乎无法 swift 破解它

我希望用户能够在 uicollectionView 中选择一个图像,并让该图像出现在详细 View Controller 中,我可以用一段文本很容易地做到这一点,当预加载静态图像数组时,我可以执行此操作。但我似乎无法使用加载了来自相机的图像的 Collection View 。

我知道我需要使用

override func performSegueWithIdentifier(identifier: String, sender: AnyObject?) {
}

这个函数用于隔离选定的单元格。

  func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
}

我确实有这些网点 @IBOutlet weak var collectionView: UICollectionView!

  var images = [UIImage]()

图像选择器将所有图像存储到这个数组中

  images.insert(newImage, atIndex: 0)

当数组被传递到 detailviewcontroller 时,我知道必须将其复制到另一个本地数组中,然后我将如何让突出显示的当前图像首先显示,可能使用 indexPath.Row

问候

最佳答案

我没有使用 segues,实际上我不太明白你的问题是什么,但我会尝试向你展示它是如何实现的。

首先,你有一个包含图像的数组,所以我相信你的图像应该作为 images[indexPath.row] 访问

假设您已经有了带有 UIImageView 的 UIViewController 类。如果是这样,你可以这样写:

func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let myVC = MyViewController()
myVC.imageView.image = images[indexPath.row]
self.presentViewController(myVC, animated: true, completion: nil)
}

用于模态或

func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let myVC = MyViewController()
myVC.imageView.image = images[indexPath.row]
self.navigationController?.pushViewController(myVC, animated: true)
}

如果您想将其显示为导航。

我相信对于 segues 它基本上是相同的,但我认为你必须使用 func prepareForSegue 来准备 segue(func performSegueWithIdentifier 只会执行它)。在 prepareForSegue 你应该检查你的 segue 的标识符

if segue.identifier == "myIdentifier" {
//your code here
}

如果这个标识符是正确的,把你的命令放到你的 myVC 那里。

关于image - 在 uicollectionview 上快速将图像传递给详细 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32914463/

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