pickerView显示为问号而不是数据?

MB4*_*B41 8 iphone swift xcode6

我正在尝试向我的iphone应用程序添加一个pickerview,但不是显示我的数组中的字符串,而是显示问号.有谁知道为什么?我一直试图弄清楚过去一小时......这是我的控制器代码,包含了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]
    }
}
Run Code Online (Sandbox Code Playgroud)

Dan*_* T. 20

您设置了选择器视图的数据源,但没有设置其委托.

结果pickerView:titleForRow:永远不会被召唤.

  • 对于想知道如何设置委托的人,请看这张图片:http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/543c1649e4b095b4c24a3d3c/1413224010678/dataSource-delegate.png?format=750w (2认同)