Я ищу, как выбрать значение выбора.Мой pickerView - это средство выбора времени, которое возвращает 08:25, 06:37, 03:24 и т.д.*
В значении pickerView нет члена 'selectRow'
Что мне нужно сделать, чтобы его использовать?
Я не использую UIPickerViewDelegate
или UIPickerViewData
, потому что мне не нужны такие функции, как numbersOfRow
.
Вот мой код:
//
// Addhoraire.swift
// School Companion
//
// Created by Cédric Loneux on 08/12/2018.
// Copyright © 2018 Cédric Loneux. All rights reserved.
//
import UIKit
class Addhoraire: ViewController {
@IBOutlet weak var nomDuCoursTextField: UITextField!
@IBOutlet weak var debutTextField: UITextField!
@IBOutlet weak var finTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let tap = UITapGestureRecognizer(target: self, action: #selector(hideKeyboard))
view.addGestureRecognizer(tap)
}
@objc func hideKeyboard() {
view.endEditing(true)
debutTextField.backgroundColor = UIColor.white
finTextField.backgroundColor = UIColor.white
debutTextField.textColor = UIColor.black
finTextField.textColor = UIColor.black
}
var hourSelected : String = ""
@IBAction func debutHoraire(_ sender: UITextField) {
finTextField.backgroundColor = UIColor.white
finTextField.textColor = UIColor.black
debutTextField.backgroundColor = UIColor(red:0.13, green:0.36, blue:1.00, alpha:1.0)
debutTextField.textColor = UIColor.white
hourSelected = "début"
let datePickerView:UIDatePicker = UIDatePicker()
datePickerView.datePickerMode = UIDatePicker.Mode.time
debutTextField.inputView = datePickerView
datePickerView.addTarget(self, action: #selector(Addhoraire.datePickerFromValueChanged), for: UIControl.Event.valueChanged)
}
@IBAction func finHoraire(_ sender: UITextField) {
debutTextField.backgroundColor = UIColor.white
debutTextField.textColor = UIColor.black
finTextField.backgroundColor = UIColor(red:0.13, green:0.36, blue:1.00, alpha:1.0)
finTextField.textColor = UIColor.white
hourSelected = "fin"
let datePickerView2:UIDatePicker = UIDatePicker()
datePickerView2.datePickerMode = UIDatePicker.Mode.time
finTextField.inputView = datePickerView2
datePickerView2.addTarget(self, action: #selector(Addhoraire.datePickerFromValueChanged), for: UIControl.Event.valueChanged)
}
@objc func datePickerFromValueChanged(sender:UIDatePicker) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH:mm"
if hourSelected == "début" {
debutTextField.text = dateFormatter.string(from : sender.date)
}
else {
finTextField.text = dateFormatter.string(from : sender.date)
}
}
@IBAction func btnRetour(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
}
@IBAction func btnValider(_ sender: UIButton) {
if (nomDuCoursTextField.text!.isEmpty || debutTextField.text!.isEmpty || finTextField.text!.isEmpty) {
let alert = UIAlertController(title: "Impossible d'ajouter le cours", message: "Veillez renseigner tout les champs obligatoires", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}