Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Bugs & Fixes 2 years ago
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.
Turn Your Knowledge into Earnings.
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:
import UIKit import Firebase import FirebaseDatabase class CreatePostViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate { @IBOutlet weak var gameTextField: UITextField! @IBOutlet weak var activityTextField: UITextField! @IBOutlet weak var consoleTextField: UITextField! @IBOutlet weak var skillTextField: UITextField! @IBOutlet weak var communicationTextField: UITextField! @IBOutlet weak var lfglfmTextField: UITextField! @IBOutlet weak var rulesTextView: UITextView! @IBOutlet weak var 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"] var console = ["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 = "" override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. //remove margin / padding from textview self.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 = REPLY 1 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
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:
import UIKit class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate { @IBOutlet weak var gameTextField: UITextField! @IBOutlet weak var activityTextField: UITextField! @IBOutlet weak var consoleTextField: UITextField! @IBOutlet weak var skillTextField: UITextField! @IBOutlet weak var communicationTextField: UITextField! @IBOutlet weak var 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"] var console = ["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 = "" weak var pickerView: UIPickerView? override func 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 screen self.view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:)))) //UIPICKER let pickerView = UIPickerView() pickerView.delegate = self pickerView.dataSource = self gameTextField.delegate = self consoleTextField.delegate = self skillTextField.delegate = self communicationTextField.delegate = self lfglfmTextField.delegate = self gameTextField.inputView = pickerView consoleTextField.inputView REPLY 1 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
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.
General Tech 9 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.