swift
1import UIKit 2 3class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource { 4 5 // 選択肢 6 let dataList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] 7 let dataList2 = ["0", "15", "30", "45"] 8 9 override func viewDidLoad() { 10 super.viewDidLoad() 11 } 12 13 func numberOfComponents(in pickerView: UIPickerView) -> Int { 14 // 表示する列数 15 return 2 16 } 17 18 func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 19 // アイテム表示個数を返す 20 21 if component == 0 { 22 // 1個目のピッカーの設定 23 return dataList.count 24 } 25 26 return dataList2.count 27 } 28 29 30 // UIPickerViewDelegate 31 32 func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 33 // 表示する文字列を返す 34 35 if component == 0 { 36 // 1個目のピッカーの設定 37 return dataList[row] 38 } 39 40 return dataList2[row] 41 } 42 43 func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 44 // 選択時の処理 45 46 if component == 0 { 47 // 1個目のピッカーの設定 48 print(dataList[row]) 49 } 50 print(dataList2[row]) 51 } 52}
やりたいこと
二つ目は実際にpickerの文字を動かした途端にエラーが起きるのでどこが間違っているの教えてもらいたいです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/08/04 17:20
退会済みユーザー
2017/08/05 10:53