ios - 将 Uiimage 传递给 View Controller

标签 ios iphone swift xcode swift3

所以我有一个名为 Paparazzo 的自定义相机,从相机拍摄的图像存储在一个名为 ImageSource 的自定义数组中。现在我宣布我会将 ImageSource 从相机 View Controller 传递到我的第二个 View Controller ,但我意识到我的图像在第二个 View Controller 上出现的位置为零。如何通过 segue 传递声明为 ImageSource 的照片中的所有图像。那是我的问题。这是我的代码。

private var photos = [ImageSource]()

@IBAction private func showMediaPicker() {
    var theme = PaparazzoUITheme()
    theme.shutterButtonColor = UIColor.blue.cgColor
    let assemblyFactory = Paparazzo.AssemblyFactory(theme: theme)
    let assembly = assemblyFactory.mediaPickerAssembly()
    let mediaPickerController = assembly.module(
        items: [],
        selectedItem: nil,
        maxItemsCount: 20,
        cropEnabled: true,
        cropCanvasSize: CGSize(width: 1280, height: 960),
        configuration: { [weak self] module in
            weak var module = module

            module?.setContinueButtonTitle("Done")

            module?.onFinish = { mediaPickerItems in
                // storing picked photos in instance var and updating UI
                self?.photos = mediaPickerItems.map { $0.image }
                self?.updateUI()
                self?.performSegue(withIdentifier: "ShowNow", sender: self?.photos)
            }
            module?.onCancel = {
                module?.dismissModule()
            }
        }
    )

    navigationController?.pushViewController(mediaPickerController, animated: true)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if (segue.identifier == "ShowNow") {
        if let pivc: view2ViewController? = segue.destination as? view2ViewController,
            let images = sender as? [UIImage] {
            pivc?.image2 = images
        }
    }
}

最佳答案

首先在secondVC中创建一个数组

 var arrImages =  Array()

然后在你当前的 VC 中做这些事情

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if (segue.identifier == "ShowNow") {
             let pivc: view2ViewController? = segue.destination as? view2ViewController

                pivc?.arrImages = images
// here images is the array of images

        }
    }

关于ios - 将 Uiimage 传递给 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42855366/

相关文章:

ios - 为 Swift UI View 创建自定义修饰符

ios - 更新到 Xcode 5 后无法将应用安装到设备

iphone - 如何以编程方式从 iPhone/iPad 将数据发送到以太网打印机?

iphone - 尝试编译 MobileSubstrate 插件 - undefined symbol

ios - 函数产生预期类型 "String",你的意思是用 "()"调用它吗

iphone - 改变图像的边界取决于图像的大小

ios - 哪个是 objective-c 中更快的运算符

用swift 3.0编译的IOS Charts Module不能导入Swift 2.3

ios - 如何在没有云功能的情况下将请求从 iOS (Swift) 发送到 Dialogflow V2 API?

ios - 在 Swift 中使用 Bool 的 View Controller 扩展