数据模型
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个数据:
和我从视图控制器中选择“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”图片。
我的问题是,我希望裁剪的图像在数据[“img3”]中更新,然后将其移回 viewController 。怎么做?
答案 0 :(得分:1)
看,你有阵列datas
。你可以做下一个:
var datas = [DataImage]()
class ViewController: UIViewController {
override func viewDidLoad() {
// fill your array with append or addObject
print(datas) // without "self."
}
答案 1 :(得分:0)
您可以使用NSNotification或委托方法在这两个viewcontrollers之间传递信息 试试这个answer