Russ
Russ

Reputation: 83

iOS Keyboard not hiding on another view tap

I have a stack view with UITextField (textView) and UIView (dropdown) in it. Its a backend-driven UI, therefore the views are not initialized on screen load. Rather theyre added after UI request is completed and setup looks like this:

func configureView(with models: [ElementType]) {
        models.forEach {
            switch $0.self {
            case .text(let model):
                let view = TextFloatView()
                view.delegate = self
                view.configure(with: model)
                stackView.addArrangedSubview(view)
            case .dropdown(let model):
                let view = DropdownField()
                view.delegate = self
                view.configure(with: model)
                stackView.addArrangedSubview(view)
            case .unknown:
                break
            }
        }
    }

While editing textView, and touching anywhere on the screen, keyboard hides properly without a problem. However when i click dropdown, focus stays on the textView and keyboard doesn't hide.

Dropdown has an action, in which i've tried adding

stackView.arrangedSubviews
        .compactMap { $0 as? TextFloatView }
        .forEach { $0.textField.resignFirstResponder()
                    view.endEditing(true) }

Doesn't work though. Please help me hide keyboard.

enter image description here

Upvotes: 1

Views: 57

Answers (0)

Related Questions