gpt4 book ai didi

ios - 无法通过当前模态转换将图像传递给另一个 UIViewController

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:59:36 24 4
gpt4 key购买 nike

我试图将图像传递到目标 UIView 的另一个 imageView,它连接到源 UIView,超过当前模态 segue。

我试图通过 segue 传递数据,并通过 Outlet 在源 UIView 中设置图像(即 NSData - 核心数据),但我收到错误 image description 在控制台中-

"fatal error: unexpectedly found nil while unwrapping an Optional value"

  //Code of destination UIView
import UIKit
import CoreData
class ReviewViewController: UIViewController {

@IBOutlet var backgroundImageView:UIImageView!
var subject:Semester!

override func viewDidLoad() {
super.viewDidLoad()
backgroundImageView?.image = UIImage(data: subject.image!)
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
backgroundImageView.addSubview(blurEffectView)

// Code of Source UIView
import UIKit
import CoreData

class SubjectDetailViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var facultyImageView:UIImageView!
var subject:Semester!

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "destinationidentifier"
{
let destinationController = segue.destinationViewController as! ReviewViewController
destinationController.backgroundImageView?.image = self.facultyImageView.image
}
}

最佳答案

您的问题是 backgroundImageView 对象为 nil,因为 destinationController 当前不在 window 层次结构中。

所以像这样改变你的prepareForSegue

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "destinationidentifier"
{
let destinationController = segue.destinationViewController as! ReviewViewController
destinationController.image = self.facultyImageView.image
}
}

现在在 ReviewViewController 中创建一个图像对象,如下所示,并在 viewDidLoad 中添加一行

var image: UIImage!

override func viewDidLoad() {
super.viewDidLoad()
self.backgroundImageView?.image = self.image
}

希望对你有帮助

关于ios - 无法通过当前模态转换将图像传递给另一个 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37936430/

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