0

I have three segments in UISegementedControl. Segment 1 is having a UITextfield. When switching between these segments, I want to disable the keyboard in the remaining two of them. (Segment 0 and Segment 2)

1 Answer 1

0

Adding view.endEditing(true) will resolve the problem. In my scenario, I considered a subview of each segmented view. subview.endEditing(true). So keyboard will automatically disappear when switching between Segments.

@IBAction func indexChanged(_ sender: UISegmentedControl) {
   for subview in self.view.subviews {
      if (subview.tag == 2 || subview.tag == 0) {
           subview.endEditing(true)
        }
     }
}
1
  • 3
    This is an answer.
    – Unheilig
    May 24, 2020 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.