1
我將一個UIPickerView添加到SpriteKit場景中。代碼如下:屏幕上出現SpriteKit中的UIPickerView
import UIKit
import SpriteKit
class MyScene: SKScene, UITextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource {
let myField = UITextField(frame: CGRectMake(UIScreen.mainScreen().bounds.size.width * 0.4, UIScreen.mainScreen().bounds.size.height * 0.35, 200, 30))
let myPickOptions = ["One", "Two", "Three"]
override func didMoveToView(view: SKView) {
super.didMoveToView(view)
let myPickerView : UIPickerView = UIPickerView()
myField.inputView = genderPickerView
myField.font = UIFont.systemFontOfSize(15)
myField.borderStyle = UITextBorderStyle.RoundedRect
myPickerView.dataSource = self
myField.delegate = self
self.view!.addSubview(myField)
}
func numberOfComponentsInPickerView(pickerView: UIPickerView!) -> Int{
return 1
}
func pickerView(pickerView: UIPickerView!, numberOfRowsInComponent component: Int) -> Int{
return myPickOptions.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return myPickOptions[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
myField.text = "\(myPickOptions[row])"
}
揀出器,當我在文本框裏面,但沒有數據(只是在拾取一些問號)自來水。
任何想法有什麼不對?
附加編輯: 當我看看兩個數據源方法時,我看到正確返回的行數,儘管它被返回了28次。也許這很正常,但看起來很奇怪。當我查看委託方法時,它看起來像第一個沒有被調用(沒有行數據被返回)。
並解決IT ... 我需要添加第二個委託:
myPickerView.delegate = self
來吧,加入你的答案。即使你自己解決了它,也很高興有一個解決的問題,以防其他人在將來也有同樣的問題! 你的大腦線索可能是委託方法沒有被調用,是吧? =] –
同意。但我必須等待兩天。 StackOverflow沒有足夠的排名 –