【问题标题】:Swift present to another page not clear cacheSwift呈现到另一个页面不清除缓存
【发布时间】:2018-08-18 11:08:17
【问题描述】:

我使用下面的代码ViewControllerHome

var myValue = 0
override func viewDidLoad() {
    super.viewDidLoad()
    ...
}

@objc func handleActionChat(sender: UITapGestureRecognizer) {
    print("Val : \(myValue)"
    myValue = 1
    print("Val : \(myValue)"
    let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
    var goController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "ViewControllerIndex")
    goController.roomId = self.sendRoom
    self.present(goController, animated: true, completion: nil)
}

首先打开ViewControllerHome,点击按钮结果为:

0
1

如果我再次转到ViewControllerHome 并单击按钮结果是:

1
1

为什么不清除缓存工作?

我想如果我每次都打开,得到01结果

【问题讨论】:

    标签: swift uiviewcontroller uistoryboard


    【解决方案1】:

    那是因为你只设置了一次var myValue = 0

    如果您想在视图控制器出现时将其设置为零,则在视图控制器出现时重置myValue

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        myValue = 0
    }
    

    【讨论】:

      猜你喜欢
      • 2010-10-13
      • 1970-01-01
      • 2011-09-20
      • 1970-01-01
      • 2023-03-03
      • 2023-03-18
      • 1970-01-01
      • 2015-08-30
      相关资源
      最近更新 更多