(Swift,Xcode6,iOS8,iPhone)
在我的UIPickerView
控件中,didSelectRow
未被调用。
Splash
设置为选择器的委托(和数据源)。Splash
扩展了UIViewController
类何时调用didSelectRow
方法?我是否需要实现某种Done
按钮,或者当用户停止旋转时此方法是否会触发?我需要实施单独的通知吗? tyvm:)
class Splash: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet var countryPicker : UIPickerView = nil
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 "\(row)"
}
func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, forComponent component: Int) -> Int {
println("Row: \(row)")
return row
}
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.
}
}
答案 0 :(得分:1)
您的签名错误,pickerView:didSelectRow:forComponent:
返回void,而不是整数。尝试:
func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, forComponent component: Int) {
println("Row: \(row)")
}
答案 1 :(得分:0)
迅速4.2
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print("selected row = \(row)") }