不知怎的,这段代码无法运行

时间:2016-05-23 10:40:22

标签: ios xcode swift

我最近尝试为iPhone创建一个BMI计算器。我从布局开始,差不多完成了。然后,当我尝试运行它时,AppDelegate.swift文件中有一个SIGABRT。我没有改变这个文件中的任何内容。这是我写的代码:

import UIKit

class FirstViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

    @IBOutlet weak var Height_txt: UITextField!
    @IBOutlet weak var Weight_txt: UITextField!

    @IBOutlet weak var Height_label: UILabel!
    @IBOutlet weak var Weight_label: UILabel!

    @IBOutlet weak var Height_picker: UIPickerView!
    @IBOutlet weak var Weight_picker: UIPickerView!

    var picker1Options = []
    var picker2Options = []

    @IBOutlet weak var Calc_button: UIButton!

    @IBOutlet weak var Result_Label: UILabel!
    @IBOutlet weak var Description_Label: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        picker1Options = ["ft","cm"]
        picker2Options = ["lbs","kg"]
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        if (pickerView.tag == 1){
            return picker1Options.count
        }else{
            return picker2Options.count
        }
    }
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        if (pickerView.tag == 1){
            return "\(picker1Options[row])"
        }else{
            return "\(picker2Options[row])"
        }
    }
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        Height_label = picker1Options[row] as! UILabel
        Weight_label = picker2Options[row] as! UILabel
    }
}

根据这个问题,我将不胜感激。谢谢!

0 个答案:

没有答案