Quantcast
Channel: Active questions tagged uipickerview - Stack Overflow
Viewing all articles
Browse latest Browse all 592

check if a textView picker view contains a certain string

$
0
0

I have an app that allows people to make posts. I am trying to check if my textView picker contains a certain text and if it does an alert should show telling them to pick again.

Image below

image

if the text contains "Job Category" I want an alert to show that says choose a category.

that field is a pickerView embedded in a textView. Here is how I set it up.

var data = ["Assembly", "Auto Care", "Electronic Help", "Item Delivery", "Handyman", "House Chores", "Junk Removal", "Lawn & Yard Care", "Moving", "Painting", "Pet Care", "Seasonal Work", "Other"]var picker = UIPickerView()func numberOfComponents(in pickerView: UIPickerView) -> Int {    return 1}func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {    return data.count}func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {    JobCategory.text = data[row]}func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {    return data[row]}let JobCategory: UITextField = {    let e = UITextField()    let attributedPlaceholder = NSAttributedString(string: "Job Category", attributes:        [NSAttributedString.Key.foregroundColor : GREEN_Theme])    e.setLeftPaddingPoints(6)    e.textColor = GREEN_Theme    e.attributedPlaceholder = attributedPlaceholder    e.setBottomBorder(backGroundColor: .white, borderColor: GREEN_Theme)    return e}()

and where I am trying to show the alert is here,

if self.JobCategory.text == "Job Category" {          let alert = UIAlertController(title: "Hold up!",message:" Choose a job category. ", preferredStyle: UIAlertController.Style.alert)          let continueButton = UIAlertAction(title: "Got it!", style: .default, handler: {(_ action: UIAlertAction) -> Void in             })          continueButton.setValue(GREEN_Theme, forKey: "titleTextColor")          alert.addAction(continueButton)          self.present(alert, animated: true, completion: nil)

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>