Я следовал инструкциям на Youtube, чтобы создать представление выбора в Swift следующим образом, но в нем есть ошибка, как описано в заголовке строки:
activityLevelField.inputView = activityPicker
Код:
import UIKit
class ViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource,UITextFieldDelegate {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return activityTypes.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return activityTypes[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
selectedActivity = activityTypes[row]
activityLevelField.text = selectedActivity
}
var selectedActivity: String?
var activityTypes = ["Less active", "active", "very active"]
func createActivityPicker(){
let activityPicker = UIPickerView()
activityPicker.delegate = self
activityPicker.dataSource = self
activityLevelField.inputView = activityPicker
}
@IBOutlet weak var activityLevelField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
createActivityPicker()
}
}