這看起來太簡單了,無法限定帖子,但我一直在這個問題上比id更長。 pickerView不顯示數組[持續時間]。運行時,模擬器只是空的領域。代碼直接從UI類複製,但它似乎缺少一些東西。swift中的pickerView不顯示數據
class FirstViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
@IBOutlet weak var durationPicker: UIPickerView!
var durations = ["72 hours", "24 hours", "6 hours", "2 hours", "20 minutes"]
var durationsValue = [72.0, 24.0, 6.0, 2.0, 0.329]
var itemSelected: String = ""
var selectedDuration: Double = 0.0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return 5
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return durations[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
itemSelected = durations[row]
selectedDuration = durationsValue[row]
}
}
你設置選擇器的數據源和委託? –