Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pickerView shows up as question marks instead of data?

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]
    }
}
like image 861
MB41 Avatar asked Nov 04 '14 23:11

MB41


1 Answers

You set your picker view's datasource, but didn't set its delegate.

As a result pickerView:titleForRow: never gets called.

like image 108
Daniel T. Avatar answered Nov 15 '22 15:11

Daniel T.