Swift:清除切换到控制器上的缓存

时间:2018-08-21 12:08:05

标签: swift controller storyboard

我有一个奇怪的问题

index.swift

override func viewDidLoad() {
    super.viewDidLoad()
    // ...
    goToPage.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleGoToPage(sender:))))
}

@objc func handleGoToPage(sender: UITapGestureRecognizer) {
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let pageController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "page")
    self.present(pageController, animated: true, completion: nil)
}

page.swift

override func viewDidLoad() {
    super.viewDidLoad()
    // ...
    pritData.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handlePritData(sender:))))
}

@objc func handlePritData(sender: UITapGestureRecognizer) {
    print("DATA")
}
  1. 我打开应用程序

  2. 我单击goToPage按钮并转到page.swift

  3. 我单击printData并打印DATA

直到这一刻,一切正常

  1. 我回到index.swift

  2. 我再次单击goToPage按钮并转到page.swift

  3. 我单击printData并打印DATA DATA

为什么要打印两次DATA

如果我退回index.swift并再次单击并转到page.swift,则我在page.swift中的功能会运行多个并打印DATA

例如,如果我20次去page.swift并单击printData,则为我打印20次DATA

为什么不为每个打开的page.swift清除缓存或清除函数缓存?

0 个答案:

没有答案