【发布时间】:2019-11-08 17:59:16
【问题描述】:
目前我必须ViewControllers。您可以使用show-segues 在ViewControllerA 和ViewControllerB 之间切换。问题是每次我切换回来时,ViewControllers 状态都会被重置。如何保存 ViewController 的设置?
从 A 到 B
@IBAction func editButtonTapped(_ sender: Any) {
let imageCollectionView = self.storyboard?.instantiateViewController(withIdentifier: "ImageCollectionVC") as! ImageCollectionViewController
self.navigationController?.pushViewController(imageCollectionView, animated: true)
}
从 B 到 A
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
tappedImage = images[indexPath.row]
performSegue(withIdentifier: "backToPopUpView", sender: self)
}
【问题讨论】:
-
“问题是每次我切换回来时,ViewControllers 状态都会被重置。”那么你实际上并没有切换回来。你能展示一些代码让我们知道你目前在做什么吗?
-
我编辑了我的问题
-
查看您的代码,您并没有在视图控制器之间来回移动,而是在每次更改时创建视图控制器的新实例。所以你实际上是在做 A > B > A1 > B1 > A2 > B2 等等,这就是为什么没有保留状态。您需要弹出视图控制器 B 才能返回到 A。顺便说一下,您也没有在 A 到 B 中使用 segue。
-
@flanker 那我该怎么做呢?
标签: ios swift uiviewcontroller segue