I've done a lot of searching but I couldn't find the solution to my issue. This is my first year of Swift, so please nothing "too advanced".
Here's my code:
class SecondViewController: UIViewController, UITextFieldDelegate, UIPickerViewDataSource, UIPickerViewDelegate {
// Properties
@IBOutlet weak var name_tf: UITextField!
@IBOutlet weak var artist_tf: UITextField!
@IBOutlet weak var sort_pkr: UIPickerView!
@IBOutlet weak var sort_lbl: UILabel!
@IBOutlet weak var sorted_lbl: UILabel!
@IBOutlet weak var next_lbl: UILabel!
let pickerData = ["Song name","Artist"]
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerData[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
sort_lbl.text = pickerData[row]
}
override func viewDidLoad() {
super.viewDidLoad()
let pickerView = UIPickerView()
pickerView.delegate = self
pickerView.dataSource = self
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
I have a feeling I'm not placing my functions in the correct spot.
For Swift 3 , use these functions:
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.