gpt4 book ai didi

ios - 从另一个 View Controller 更新/更改数组值

转载 作者:搜寻专家 更新时间:2023-10-31 23:01:10 25 4
gpt4 key购买 nike

数据模型

class DataImage {
var userId: String
var value: Double
var photo: UIImage?
var croppedPhoto: UIImage?

init(userId:String, value: Double, photo: UIImage?, croppedPhoto: UIImage?){
self.userId = userId
self.value = value
self.photo = photo
self.photo = croppedPhoto
}

}

ViewController(tableView)

var photos = [DKAsset]() //image source
var datas = [DataImage]()
override func viewDidLoad() {
super.viewDidLoad()
self.loadDataPhoto()
}

func loadDataPhoto(){
var counter = 0
for asset in photos{
asset.fetchOriginalImageWithCompleteBlock({ image, info in // move image from photos to datas

let images = image
let data1 = dataImage(userId: "img\(counter+1)", value: 1.0, photo: images, croppedPhoto: images)
self.datas += [data1]
counter++

})
}
}

根据该代码,假设我有 5 个数据:

  • dataImage(userId: "img1", value: 1.0, photo: images, croppedPhoto: 图片)
  • dataImage(userId: "img2", value: 1.0, photo: images, croppedPhoto: 图片)
  • dataImage(userId: "img3", value: 1.0, photo: images, croppedPhoto: 图片)
  • dataImage(userId: "img4", value: 1.0, photo: images, croppedPhoto: 图片)
  • dataImage(userId: "img5", value: 1.0, photo: images, croppedPhoto: 图片)

我从 View Controller 中选择“img3”并成功将其移动到cropviewController

CropViewController

var datasCrop: dataImage?
override func viewDidLoad() {
super.viewDidLoad()
if let datasCrop = datasCrop{
// beforeImage.image = datasCrop.photo
photoId.text = datasCrop.userId
self.cropView.imageToCrop = datasCrop.photo

}
}

@IBAction func handleCropButton(sender: UIButton)
{
if let croppedImage = cropView.croppedImage()
{
croppedImage //theCropped img3's cropped image
}
}

croppedViewController 中,我裁剪了“img3”图像。

我的问题是,我希望在 datas["img3"] 中更新裁剪后的图像并将其移回 viewController。如何做到这一点?

最佳答案

看,您有数组 datas。您可以执行下一步:

var datas = [DataImage]()
class ViewController: UIViewController {
override func viewDidLoad() {
// fill your array with append or addObject
print(datas) // without "self."
}

关于ios - 从另一个 View Controller 更新/更改数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34915370/

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