I am trying to set up two pickerviews on one view, but I don't want to show the wheels, I just want the wheels to pop up when the specific text box is clicked. I can get it to work for one Pickerview, but when I try and add the second, the pickerviews no longer work.
I've tried to use "tags" but since I'm not expicitly using UIPickerView!, I can't use the tags, I don't think.
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate{
@IBOutlet weak var cornerText: UITextField!
@IBOutlet weak var brandText: UITextField!
// PICKER VIEW CODE
let Corner = ["LF", "RF", "RR", "LR", "5th"]
let Brand = ["Brand1", "Brand2", "Brand3", "Brand4", "Brand5"]
func numberOfComponents(in cornerPickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ cornerPickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if cornerText.isEditing{
return Corner.count
}
else if brandText.isEditing{
return Brand.count
}
else {
return 0
}
}
func pickerView(_ cornerPickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if cornerText.isEditing{
return Corner[row]
}
else if brandText.isEditing{
return Brand[row]
}
else {
return nil
}
}
var cornerIndex: Int!
var brandIndex: Int!
func pickerView(_ cornerPickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if cornerText.isEditing{
cornerText.text = Corner[row]
cornerIndex = row
}
else if brandText.isEditing{
brandText.text = Brand[row]
brandIndex = row
}
else{
return
}
}
func createPickerView(){
if cornerText.isEditing{
let cornerPickerView = UIPickerView()
cornerPickerView.delegate = self
cornerText.inputView = cornerPickerView
}
else if brandText.isEditing{
let cornerPickerView = UIPickerView()
cornerPickerView.delegate = self
brandText.inputView = cornerPickerView
}
else {
return
}
}
func dismissPickerView(){
let toolBar = UIToolbar()
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(self.dismissKeyboard))
toolBar.setItems([doneButton], animated: false)
toolBar.isUserInteractionEnabled = true
if cornerText.isSelected{
cornerText.inputAccessoryView = toolBar
}
else {
brandText.inputAccessoryView = toolBar
}
}
@objc func dismissKeyboard(){
view.endEditing(true)
// Put anything that must pop up based on the corner here
I would like both pickerviews to work, right now neither pickerview's display.