私はUIPickerViewを使用していて、エラーが発生しています( '[String]'型の戻り式を 'String'型/ UIPickerView型に変換できません)。ここに私のコードです。'[String]'型の戻り式を 'String'型に変換できません。/UIPickerView
// where the picker view is set up.
let cubesToWorkWith = ["3X3", "2X2", "4X4", "5X5", "6X6", "7X7", "Skewb", "Square-One"]
let threeByThreeArray = ["OLL", "PLL"]
@IBOutlet weak var pickerViewOutlet: UIPickerView!
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 2
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
let row = pickerView.selectedRow(inComponent: 0)
print("this is the pickerView\(row)")
switch row {
case 0:
return threeByThreeArray.count
default:
return cubesToWorkWith.count
}
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
switch row {
case 0:
return threeByThreeArray[row]
default:
return getArrayForRow(row: row)
}
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
cubeSelected = Int16(row)
}
func getArrayForRow(row: Int) -> [String] {
switch row {
case 0:
return threeByThreeArray
default:
return cubesToWorkWith
}
}
}
}
と私は「getArrayForRow(行:行)を返す」でtitleForRow内部のスイッチケースでエラーを取得する事前に任意の助け ありがとう!!!!
'getArrayForRow'は' [文字列]を返し 'と' pickerView(_:titleForRow:...) ''文字列を返します '?。あなたは何を期待しましたか?配列と文字列のマジック変換? – user28434
P.これは私の他の質問からのフォローアップの質問です:http://stackoverflow.com/questions/42316756/uipickerview-multi-components-in-swift –
'getArrayForRow(row:row)'は 'Array'を返しますが、 'String? 'が期待されます。私は期待される出力を理解していませんが、 'getArrayForRow(row:row).first'はクラッシュを修正し、うまくいけば問題を理解する助けになります:-) – shallowThought