Posted on 31 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
I am trying to create a form in which each text field has a UIPickerView which the user can use to select the option needed. I need a to use a different array of information for each text field but I can't seem to get it to work and I have been stuck on it for quite a while now.
I have had a method which was possibly working but I couldn't then retrieve the data from the text field for Firebase due to each field having the same name.
Here is my code so far, this is the latest method that I have tried that doesn't work:
importUIKitimportFirebaseimportFirebaseDatabaseclassCreatePostViewController:UIViewController,UIPickerViewDataSource,UIPickerViewDelegate,UITextFieldDelegate{@IBOutletweakvar gameTextField:UITextField!@IBOutletweakvar activityTextField:UITextField!@IBOutletweakvarconsoleTextField:UITextField!@IBOutletweakvar skillTextField:UITextField!@IBOutletweakvar communicationTextField:UITextField!@IBOutletweakvar lfglfmTextField:UITextField!@IBOutletweakvar rulesTextView:UITextView!@IBOutletweakvar descriptionTextView:UITextView!var games =["Assassin's Creed Origins","Battlefield 1","Call of Duty: Advanced Warfare","Call of Duty: Black Ops III","Call of Duty: Ghosts","Call of Duty: Infinite Warfare","Call of Duty: Modern Warfare Remastered","Call of Duty: WWII","Destiny","Destiny 2","Fifa 16","Fifa 17","Fifa 18","Rocket League"]varconsole=["Xbox One","Xbox 360","Playstation 4","Playstation 3"]var skill =["Achiever","Explorer","Killer","Socializer"]var communication =["Mic","No Mic"]var lfglfm =["LFG","LFM"]var itemSelected =""overridefuncviewDidLoad(){super.viewDidLoad()// Do any additional setup after loading the view.
//remove margin / padding from textviewself.rulesTextView.textContainerInset =.zero
self.rulesTextView.contentInset =UIEdgeInsetsMake(0,-5,0,0)// self.descriptionTextView.textContainerInset = .zero
// self.descriptionTextView.contentInset = UIEdgeInsetsMake(0, -5, 0, 0)
//allow tap on screen to remove text field input from screen
self.view.addGestureRecognizer(UITapGestureRecognizer(target:self.view, action:#selector(UIView.endEditing(_:))))//UIPICKER
let pickerView =UIPickerView()
pickerView.delegate =
Your code is almost right. I would just store a class attribute with the UIPickerView so you can reload the components upon textField editing status change. For that purpose, you have also to set the textField delegates.
Here a working example with the adjustments I just commented:
importUIKitclassViewController:UIViewController,UIPickerViewDataSource,UIPickerViewDelegate,UITextFieldDelegate{@IBOutletweakvar gameTextField:UITextField!@IBOutletweakvar activityTextField:UITextField!@IBOutletweakvarconsoleTextField:UITextField!@IBOutletweakvar skillTextField:UITextField!@IBOutletweakvar communicationTextField:UITextField!@IBOutletweakvar lfglfmTextField:UITextField!var games =["Assassin's Creed Origins","Battlefield 1","Call of Duty: Advanced Warfare","Call of Duty: Black Ops III","Call of Duty: Ghosts","Call of Duty: Infinite Warfare","Call of Duty: Modern Warfare Remastered","Call of Duty: WWII","Destiny","Destiny 2","Fifa 16","Fifa 17","Fifa 18","Rocket League"]varconsole=["Xbox One","Xbox 360","Playstation 4","Playstation 3"]var skill =["Achiever","Explorer","Killer","Socializer"]var communication =["Mic","No Mic"]var lfglfm =["LFG","LFM"]var itemSelected =""weakvar pickerView:UIPickerView?overridefunc viewDidLoad(){super.viewDidLoad()// Do any additional setup after loading the view.
//remove margin / padding from textview
// self.descriptionTextView.textContainerInset = .zero
// self.descriptionTextView.contentInset = UIEdgeInsetsMake(0, -5, 0, 0)
//allow tap on screen to remove text field input from screenself.view.addGestureRecognizer(UITapGestureRecognizer(target:self.view, action:#selector(UIView.endEditing(_:))))//UIPICKER
let pickerView =UIPickerView()
pickerView.delegate =self
pickerView.dataSource =self
gameTextField.delegate =selfconsoleTextField.delegate =self
skillTextField.delegate =self
communicationTextField.delegate =self
lfglfmTextField.delegate =self
gameTextField.inputView = pickerView
consoleTextField.inputView
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that
you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice
sessions to improve your knowledge and scores.
manpreet
Best Answer
2 years ago
I am trying to create a form in which each text field has a UIPickerView which the user can use to select the option needed. I need a to use a different array of information for each text field but I can't seem to get it to work and I have been stuck on it for quite a while now.
I have had a method which was possibly working but I couldn't then retrieve the data from the text field for Firebase due to each field having the same name.
Here is my code so far, this is the latest method that I have tried that doesn't work: