swift - 在 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 中。
解决方案
推荐阅读
- regex - 如何根据字符位置查找具有条件的行?
- office365 - 是否可以将成员添加到对其 SharePoint 网站具有读取权限的 office 365 组
- postgresql - 在字符变化字段上使用分组时查询慢
- c++ - 前后增量
- javascript - 将状态数组值转换为键值对
- r - 带有 networkD3 的桑基图 - 创建链接
- java - Antlr 语法无法提供所需的 AST
- python - 将响应类型更改为 str、bytes 或 os.Pathlike
- java - JavaFX FXMLLoader InvocationTargetException 和 NullpointerException
- php - 方法 Illuminate\Database\Query\Builder::languages 不存在