我想添加一個pickerview到我的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]
}
}
對於任何人想知道如何設置委託,看到這個圖片:http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/543c1649e4b095b4c24a3d3c/1413224010678/dataSource-delegate。 png?format = 750w – scottyseus 2015-12-09 00:43:05
或者添加'self.YourIBOutletForPicker.delegate = self' – 2017-11-27 03:08:27