pickerView显示为问号而不是数据? [英] pickerView shows up as question marks instead of data?

查看:64
本文介绍了pickerView显示为问号而不是数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的iPhone应用程序添加pickerview,但是没有显示数组中的字符串,而是显示了问号.有人知道为什么吗?在过去的一个小时里,我一直在努力解决问题……这是我的包含pickerview的控制器代码:

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.

结果是pickerView:titleForRow:从未被调用.

这篇关于pickerView显示为问号而不是数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆