我正在尝试填充3个选择器视图。由于某种原因,所有这些都显示为空白。知道为什么吗?
import UIKit
class ViewController2: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var seconds: UIPickerView!
@IBOutlet weak var minutes: UIPickerView!
@IBOutlet weak var distance: UIPickerView!
var meters = [200, 400, 600, 800, 1000, 1200]
override func viewDidLoad() {
super.viewDidLoad()
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
switch pickerView {
case minutes:
return 100
case seconds:
return 59
case distance:
return (meters.count - 1)
default:
return 10
}
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
switch pickerView {
case minutes:
return String(row)
case seconds:
return String(row)
case distance:
return String(meters[row])
default:
return "ERROR 404"
}
}
}
答案 0 :(得分:2)
在viewDidLoad
组中
self.seconds.delegate = self
self.seconds.dataSource = self
以此类推,对于每个pickerView