gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 21:49:32 25 4
gpt4 key购买 nike

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

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]
}
}

最佳答案

您设置了选择器 View 的数据源,但没有设置它的委托(delegate)。

因此 pickerView:titleForRow: 永远不会被调用。

关于iphone - pickerView 显示为问号而不是数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26747115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com