Swift初心者です。
Pickerで選択した値をラベルに表示しようとしています。
以下のコードを実行すると、当然かもしれませんが、list[1]を選択すると、ラベルに設定時間'list[1]の値'月'list[1]の値'が表示されます。list[3]を選択しても同じような表示になります。
label.text = "誕生日" + list[component][row] + "月" + list[component][row] + "日"
太字の部分の記載方法を教えていただければ幸いです。
回答、お願い致します。
var list: [[String]] = [ ["誕生日"], ["1"], ["月"], ["1"], ["日"] ] for a in 2...12 { var b : String = "" b = String(a) list[1].append(b) } for a in 2...31 { var b : String = "" b = String(a) list[3].append(b) } func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { return list.count } func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { return list[component].count } func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView { let label = UILabel(frame: CGRectMake(0, 0, pickerView.frame.width/CGFloat(list.count), 44)) label.text = list[component][row] as String label.textAlignment = NSTextAlignment.Center return label } func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { label.text = "誕生日" + list[component][row] + "月" + list[component][row] + "日" }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。