gpt4 book ai didi

ios - 使用 Date UIPicker 和 Normal Picker 设置文本字段时出错,我尝试了很多东西但出现错误

转载 作者:行者123 更新时间:2023-11-28 13:29:47 25 4
gpt4 key购买 nike

我正在使用 Datepicker 和 Normal Picker 设置文本字段,但出现相同的错误,我无法执行此操作。下面是代码

class SetupViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {




@IBOutlet weak var genderPickerInput: UITextField!

@IBOutlet weak var datePickerInput: UITextField!
private var datepicker: UIDatePicker?
var genderPickerData: [String] = [String]()

override func viewDidLoad() {
super.viewDidLoad()
let genderPicker = UIPickerView()
genderPickerInput.inputView = genderPicker
genderPicker.delegate = self
datepicker = UIDatePicker()
datepicker?.datePickerMode = .date
datepicker?.addTarget(self, action: #selector(ViewController.dateChanged(datepicker)), for: .valueChanged)

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.viewTapped(UITapGestureRecognizer)))
view.addGestureRecognizer(tapGesture)

datePickerInput.inputView = datepicker


genderPickerData = ["Male", "Female", "Other"]
// Do any additional setup after loading the view.
}

// MARK: UIPickerView Delegation

func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

func pickerView( _ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return genderPickerData.count
}

func pickerView( _ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return genderPickerData[row]
}

func pickerView( pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
genderPickerInput.text = genderPickerData[row]
}
func dateChanged(datepicker : UIDatePicker){
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy"
datePickerInput.text = dateFormatter.string(from: datepicker.date)
view.endEditing(true)

}


func viewTapped(gestureRecognizer: UITapGestureRecognizer){
view.endEditing(true)



}
}

错误 1

Type 'ViewController' has no member 'dateChanged'

错误 2

Type 'ViewController' has no member 'viewTapped', did you mean 'viewLoaded'

最佳答案

您需要删除 ViewController. 或将其替换为 self.

datepicker?.addTarget(self, action: #selector(self.dateChanged), for: .valueChanged) 
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.viewTapped))

func dateChanged(_ datepicker : UIDatePicker){}
func viewTapped(_ gestureRecognizer: UITapGestureRecognizer){}

关于ios - 使用 Date UIPicker 和 Normal Picker 设置文本字段时出错,我尝试了很多东西但出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57568799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com