Xcode Picker视图不起作用

时间:2016-05-14 16:30:12

标签: xcode uipickerview

我正在尝试在我的应用中显示三个位置的选择器视图。这是我到目前为止的代码:

import UIKit

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

@IBOutlet weak var BillAmount: UITextField!
@IBOutlet weak var PercentTip: UITextField!
@IBOutlet weak var SalesTax: UITextField!
@IBOutlet weak var TipAmount: UILabel!
@IBOutlet weak var TotalAmount: UILabel!
@IBOutlet weak var TaxAmount: UILabel!
@IBOutlet var PlacePicker: UIPickerView!

var placeArray = ["Atlanta","Boston","New York City"]

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    PlacePicker.delegate = self
    PlacePicker.dataSource = self
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func btnCalPress(sender: AnyObject) {
    let tipPer = Double(PercentTip.text!)! / 100
    let billAmt = Double(BillAmount.text!)
    let salesTax = Double(SalesTax.text!)! / 100

    let tipAmt = Double(billAmt! * tipPer)
    let taxAmt = Double(billAmt! * salesTax)
    let totalAmt = tipAmt + taxAmt + billAmt!

    let tipAmountFormat = round(tipAmt * 100) / 100
    let taxAmountFormat = round(taxAmt * 100) / 100
    let totalPayFormat = round(totalAmt * 100) / 100

    TipAmount.text = "Tip: $\(tipAmountFormat)"
    TaxAmount.text = "Tax: $\(taxAmountFormat)"
    TotalAmount.text = "Total: $\(totalPayFormat)"
}

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    return placeArray[row]
}

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return placeArray.count
}

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

}

这是一个小费计算器,我希望用户选择他们所在的城市。当我运行它时,它说它成功了,但后来我收到了这个错误:

enter image description here

我从故事板上知道它的连接,但我已经重做了,我很确定我做得正确。我做错了什么?

0 个答案:

没有答案