私のコードは次のとおりです。UIPickerViewDelegate Xcodeの8スウィフト3
Type 'ViewController' does not conform to protocol 'UIPickerViewDataSource'
どれソリューション:
class ViewController: UIViewController,UIPickerViewDelegate, UIPickerViewDataSource {
@IBOutlet weak var picherview: UIPickerView!
var prodotti = ["AAAAA", "VVVV", "CCCC"]
override func viewDidLoad() {
super.viewDidLoad()
self.picherview.dataSource = self
self.picherview.delegate = self
// 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 numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerview(_ : UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return prodotti.count
}
func pickerview(_ : UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return prodotti[row]
} //ci consente di determinare quale riga è stata selezionata
func pickerview(_ : UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print("Hai selezionato: \(prodotti[row])")}
}
このコードはエラーがありますか?
「UIPickerViewDataSource」と「UIPickerViewDelegate」のドキュメントを参照してください。すべてのメソッドはSwift 3で変更されました。 – rmaddy