gpt4 book ai didi

swift - 快速将图像从一个 View Controller 传递到另一个 View Controller

转载 作者:行者123 更新时间:2023-11-30 10:23:23 26 4
gpt4 key购买 nike

我尝试使用 segue 将图像从一个 View Controller 传递到另一个 View Controller ,但图像为空且无法使用。

这里是mainViewController.swift,所有日志都显示正确的值。

func imagePickerController(picker:UIImagePickerController!,didFinishPickingMediaWithInfo info: NSDictionary!){
var i:UIImage = info.objectForKey(UIImagePickerControllerOriginalImage) as UIImage
NSLog("%f, %f", i.size.width, i.size.height);

orignal = i
NSLog("iamge %@", orignal)
performSegueWithIdentifier("showPhoto", sender: self)
dismissModalViewControllerAnimated(false)
}

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
var imageEditcontroller:ImageEditViewController = segue.destinationViewController as ImageEditViewController

imageEditcontroller.editImage = orignal
NSLog("iamge %@", imageEditcontroller.editImage)
}

这是另一个 View Controller “ImageEditViewController.swift”

import UIKit

class ImageEditViewController: UIViewController {

@IBOutlet var imagEditView : UIImageView

var editImage:UIImage=UIImage()

@IBAction func doDecorateBtn(sender : AnyObject) {
print("here text chage5")
}

@IBAction func doEmailBtn(sender : AnyObject) {
print("here text chage6")
}

init(coder aDecoder: NSCoder!) {
super.init(coder: aDecoder)
NSLog("iamge2 %@", editImage)
}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
NSLog("iamge1 %@", editImage)
}

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the vie
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

所以查看此 View ​​ Controller 中的日志,var editImage 未初始化为正确的值。刚刚接触 IOS,感谢您的帮助。

最佳答案

我明白了,问题不是我想的那样,图像可以传递给另一个 View Controller 。该问题是由于弃用 API 造成的。 “解除ModalViewControllerAnimated”。更详细的请参阅这个问题。 dismissModalViewControllerAnimated deprecated

关于swift - 快速将图像从一个 View Controller 传递到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24381366/

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