samedi 25 juin 2016

Xcode error 'Ambiguous reference to member pickerView(_:numberOfRowsInComponent:)'

This error is generated on each of the lines similar to the following line: let thousandsComponent = pickerView.selectedRowInComponent(dollarComponent_1) This is an odd error considering the following code used which I believe is correct: func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { return pickerData.count } Background: I have programattically created a UIPickerView that I bring up when a text field is touched and dismiss it with a touch outside of the picker view. I added the func updateFoodnDrinkLabel() so that I can update the results label that reflects the values chosen in the picker. I am trying to designate each component to reflect the monetary value it represents, i.e., thousands, hundreds, and so on. If I add a picker to the view in the storyboard and replace 'pickerView' its title the error goes away. Apparently what I am trying to do does not apply to UIPickerViews created programmatically. The code is as follows: class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate { @IBOutlet weak var pickerTextField: UITextField! @IBOutlet weak var foodAndDrinkTextField: UITextField! var pickerData = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] let dollarComponent_1 = 0 let dollarComponent_2 = 1 let dollarComponent_3 = 2 let dollarComponent_4 = 3 let centsComponent_5 = 4 let centsComponent_6 = 5 override func viewDidLoad() { super.viewDidLoad() let pickerView = UIPickerView() pickerView.delegate = self foodAndDrinkTextField.inputView = pickerView } func updateFoodnDrinkLabel() { let thousandsComponent = pickerView.selectedRowInComponent(dollarComponent_1) let hundredsComponent = pickerView.selectedRowInComponent(dollarComponent_2) let tensComponent = pickerView.selectedRowInComponent(dollarComponent_3) let onesComponent = pickerView.selectedRowInComponent(dollarComponent_4) let cents1_Component = pickerView.selectedRowInComponent(centsComponent_5) let cents2_Component = pickerView.selectedRowInComponent(centsComponent_6) Any help would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire