How to configure the second component using UIPickerView

I found several similar questions, but none of the solutions corresponded to my situation, and most of them were in objective-c, which I do not know.

I am trying to create a timer from minutes and seconds, but I cannot figure out how to connect the second component.

How to configure the second component using UIPickerView?

This is what I have so far:

enter image description here

TimeViewController.swift

class TimeViewController: UIViewController, UIPickerViewDelegate { @IBOutlet weak var timeSegueLabel: UILabel! let minutes = Array(0...9) let seconds = Array(0...59) func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { return 2 } func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { return minutes.count } func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! { return String(minutes[row]) } override func viewDidLoad() { super.viewDidLoad() } } 
+5
source share
1 answer

Thanks to @Bluehound for pointing me in the right direction. I needed to look at objective-c on GitHub to find out how to do this, this is the answer I was looking for:

TimeViewController:

 class TimeViewController: UIViewController, UIPickerViewDelegate { @IBOutlet weak var timeSegueLabel: UILabel! let minutes = Array(0...9) let seconds = Array(0...59) var recievedString: String = "" func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { return 2 } func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { //row = [repeatPickerView selectedRowInComponent:0]; var row = pickerView.selectedRowInComponent(0) println("this is the pickerView\(row)") if component == 0 { return minutes.count } else { return seconds.count } } func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! { if component == 0 { return String(minutes[row]) } else { return String(seconds[row]) } } override func viewDidLoad() { super.viewDidLoad() timeSegueLabel.text = recievedString } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } 

This is the result:

enter image description here

+13
source

All Articles