アプリ開発初心者です。
PickerViewを同じ画面内に二つ配置し、
それぞれ別の値を保持し、ラベルに出力しようと思っているのですが、
以下のコードで実行すると、二つとも同じ値で表示されてしまいます。
何か解決はありますでしょうか?
回答、よろしくお願い致します。
@IBOutlet weak var pickerview1: UIPickerView!
var list: [[String]] = [
["容量"],
["30"],
["ml"]
]
@IBOutlet weak var pickerview2: UIPickerView!
var list2: [[String]] = [
["0"],
["時"],
["0"],
["分"]
]
override func viewDidLoad() {
for a in 31...150 {
var b : String = ""
b = String(a)
list[1].append(b)
}
for c in 1...23 {
var d : String = ""
d = String(c)
list2[0].append(d)
}
for e in 1...59 {
var f : String = ""
f = String(e)
list2[2].append(f)
}
pickerview1.dataSource = self
pickerview1.delegate = self
pickerview2.dataSource = self
pickerview2.delegate = self
}
@IBOutlet weak var label1: UILabel!
func numberOfComponentsInPickerView(pickerview1: UIPickerView) -> Int {
return list.count
}
func pickerView(pickerview1: 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.textColor = colorPattern.main()
label.text = list[component][row] as String
label.textAlignment = NSTextAlignment.Center
return label
}
@IBOutlet weak var label2: UILabel!
func numberOfComponentsInPickerView1(pickerview2: UIPickerView) -> Int {
return list2.count
}
func pickerView2(pickerview3: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return list2[component].count
}
func pickerView2(pickerView2: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView {
let label2 = UILabel(frame: CGRectMake(0, 0, pickerView2.frame.width/CGFloat(list2.count), 44))
//label.textColor = colorPattern.main()
label2.text = list2[component][row] as String
label2.textAlignment = NSTextAlignment.Center
return label2
}
func pickerView(pickerview1: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
label1.text = "容量" + list[component][row] + "ml"
}
func pickerView2(pickerview3: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
label2.text = "時間" + list2[component][row]
}