首页 > 解决方案 > 在 Perform Segue 上传递参数返回 nil

问题描述

我有一个显示 5 秒的闪屏。在这段时间之后,我以编程方式调用另一个 ViewController(VC_Products) 并希望传递参数,但我的 ViewController 没有收到任何东西。

override func viewDidLoad() {
    super.viewDidLoad()
    //here we set a timer to start after a given amount of seconds the ProductViewController
    _ = Timer.scheduledTimer(timeInterval: 5.0, target: self, selector: #selector(timeToMoveOn), userInfo: nil, repeats: false)
}


@objc func timeToMoveOn() {

    //change root navigation controller
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.changeRootViewControllerToSWRevealViewController()

    self.performSegue(withIdentifier: "splashscreen_to_products", sender: self)

}


override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if (segue.identifier == "splashscreen_to_products") {

        if let vc: VC_Products = segue.destination as? VC_Products {
               vc.titleremote = "variableToPass"
        }

    }
}  

在 VC_Products 中:

我有以下内容:

var titleremote:String = ""

并且它不会更改为“variableToPass”。什么都没发生!为什么?

也许我的序列是错误的? 在此处输入图像描述

更新:

似乎将 rootview 控制器更改为 SWRevealViewController 是我无法传递参数的原因。我删除了 SWrevealViewController 并且它起作用了。不知何故,我需要 SWRevealViewController 有一个左侧菜单,但是我无法传递数据。我想从启动画面中的远程 URL 加载图像,然后将它们传递到 VC_Products 呈现图像的位置。这是不可能的。我搜索了两天,找到一种通过 SWRevealViewController 传递图像的方法,但没有成功。我现在将采用不同的方式,将启动画面中加载的图像保存到临时文件夹,然后将图像从那里加载到 VC_Products 中。这就是我讨厌 iOS 编码的地方。故事板和控制器之间的整个导航是可怕的,因为布局约束和调试在 iOS 中。

标签: swiftparameter-passing

解决方案


推荐阅读