【发布时间】:2019-05-26 21:27:03
【问题描述】:
我的大学小项目需要帮助。我有两个 ViewController。 第一个 - DietViewController 第二 - WaterBalanceViewController(使用 SPStorkController)
我需要在我的 DietVC 中填写 CircleProgressView。
当我点击Drink ->
@IBAction func drinkAction(_ sender: UIButton) {
let controller = WaterBalanceViewController()
let transitionDelegate = SPStorkTransitioningDelegate()
controller.transitioningDelegate = transitionDelegate
controller.modalPresentationStyle = .custom
transitionDelegate.customHeight = 620
transitionDelegate.showIndicator = false
self.present(controller, animated: true, completion: nil)
}
然后打开 SPStorkController - 我的 secondVC
接下来,当我在我的 secondVC 中单击按钮 Drink 时,我必须保存:我刚刚喝了多少。例如将此变量称为justDrunk。在我的第一个VC 中,我有var currentAmountOfWater = Float()这是将传递给CircleProgressView 的值。我尝试保存:
@objc func pressButton(_ sender: UIButton){
print("Hello")
self.justDrunk = Float(textField.text!)!
let vc = DietViewController()
vc.currentAmountOfWater += justDrunk
vc.currentAmountOfWater += justDrunk
UserDefaults.standard.set(vc.currentAmountOfWater, forKey: "currentAmountOfWater")
print(UserDefaults.standard.float(forKey: "currentAmountOfWater"))
self.dismiss(animated: true, completion: nil)
}
当我尝试打印时,我可以看到我的值没有保存。总是打印justDrunk的结果。
然后我想在我的 firstVC 中使用我的currentAmountOfWater。
在 viewDidLoad `var valueForWater = currentAmountOfWater/maxAmountOfWater
waterProgress.progressColor = UIColor(red: 0, green: 122/255, blue: 1, alpha: 1)
waterProgress.setProgressWithAnimation(duration: 1, value: valueForWater)
拜托,有人帮助我。如何在 secondVC 中输入数据,将数据传递给 firsVC 并在 CicrleProgressView 中全部显示。也许您可以编写一个代码,每 24 小时将currentAmountOfWater 重置为零。
谢谢!
【问题讨论】:
标签: swift xcode nsuserdefaults userdefaults