【问题标题】:Why segues does not work? can not switch view为什么segues不起作用?无法切换视图
【发布时间】:2021-02-21 04:54:25
【问题描述】:

**不太清楚为什么按钮计算时视图没有改变 被按下? 可能的原因是什么?你能帮忙吗?

import UIKit
class CalculateViewController: UIViewController {
    @IBOutlet weak var heightLabel: UILabel!
    @IBOutlet weak var weightLabel: UILabel!
    @IBOutlet weak var heightSlider: UISlider!
    @IBOutlet weak var weightSlider: UISlider!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    @IBAction func heightSlided(_ sender: UISlider) {
        var currentHeightValue = sender.value
        let roundedHeightValue = String(format: "%.2f", currentHeightValue)
        heightLabel.text = "\(roundedHeightValue)m"
    }
    
    @IBAction func weightSlided(_ sender: UISlider) {
        var currentWeightValue = sender.value
        let roundedWeightValue = String(format: "%.0f", currentWeightValue)
        weightLabel.text = "\(roundedWeightValue)kg"
    }
    
    @IBAction func calculateBMI(_ sender: UIButton) {
        var squareOfHeight = Float(pow(heightSlider.value, 2.0))
        var BMI = weightSlider.value / squareOfHeight
        
        self.performSegue(withIdentifier: "goToResult", sender: self)
   
    }
    
}

【问题讨论】:

  • 你需要做一点调试... calculateBMI() 真的被调用了(可能它没有连接到右键)?如果它 is 被调用,请检查您的 Segue 的设置......也许是错字?例如您在 Storyboard 中输入了“gotoResult”而不是“goToResult”?

标签: ios swift view segue


【解决方案1】:

试试这个..

让storyBoard: UIStoryboard = UIStoryboard(name: "Name 故事板”,捆绑:无) if let push = storyBoard.instantiateViewController(withIdentifier: "Name Storyboar ID") as? Name View Controller { self.navigationController?.pushViewController(推,动画:真) }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    相关资源
    最近更新 更多