在Xcode中的一个按钮上执行多个操作

时间:2018-06-07 21:36:19

标签: swift xcode uibutton ibaction

我一直收到错误:

  

致命错误:在解包可选值时意外发现nil

组合两个动作时。不确定该怎么做,因为我现在只使用Xcode几天了。我想要做的是按下按钮时执行多次计算/操作。先谢谢你的意见!

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var priceTextField: UITextField!
    @IBOutlet weak var payoutTextField: UITextField!
    @IBOutlet weak var leasingTextField: UITextField!
    @IBOutlet weak var payoutLabel: UILabel!
    @IBOutlet weak var leasingsumLabel: UILabel!
    @IBOutlet weak var restsumLabel: UILabel!

    @IBAction func loanCalculate(_ sender: Any) {
        let price: Double = Double(priceTextField.text!)!
        let twentyPercentOfPrice: Double = price * 0.2
        payoutLabel.text = String(twentyPercentOfPrice)
        let leasingsum: Double = Double(leasingTextField.text!)!
        let thirtyPercentOfLeasing: Double = leasingsum * 0.3
        leasingsumLabel.text = String(thirtyPercentOfLeasing)
    }
}

0 个答案:

没有答案