I am trying to add a pickerview to my iphone application but instead of showing string from my array it shows question marks. Does anyone know why? I've been trying to figure it out for the past hour... Here is my code of the controller that contains the pickerview:
class NewIssueViewController: UIViewController, UIPickerViewDelegate {
var componentArr = ["component1","component2","component3","component4"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func CancelPressed(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func AddPressed(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
func numberOfComponentsInPickerView(pickerView: UIPickerView!) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView!, numberOfRowsInComponent component: Int) -> Int {
return componentArr.count
}
func pickerView(pickerView: UIPickerView!, titleForRow row: Int, forComponent component: Int) -> String! {
return componentArr[row]
}
}
You set your picker view's datasource, but didn't set its delegate.
As a result pickerView:titleForRow:
never gets called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With