1

I'm trying to make a facebook style input bar for when a user wants to make a comment. To do that I created a custom UIView in an .xib which holds my buttons and input UITextView (generally I much prefer using storyboard to programatically creating constraints). I linked the bottom constraint of that UITextVuew to the bottom of my view with a constant that represents the height of the keyboard so it will appear right above the keyboard. So far so good.

I want the UITextView to be loaded but to remain hidden and unactionable until the user hits the comment button. I then have the main view controller attempt to make the UITextView a first responder which should trigger the WillShowKeyboard function in which I reset the constraint on my text view as well as make my custom view visible and actionable.

The issue is, the textview cannot become the first responder for some reason. I think its because its "outside the view hierarchy" or maybe because user interaction is disabled at the moment of the call. I also tried calling the first responder inside my custom view which didn't do anything either.

I want this input text bar to be a custom view/cell so i can reuse it through the project, I'd prefer not to build it programatically in each place where I want to use it. Is there a way to force include my custom view into the view hierarchy (does that even make sense?). Also is there a way to force the keyboard to show without any text view actually becoming the first responder because that would be an adequate solution as well.

First time asking a question on stack overflow so sorry if anything is unclear! Thanks

1 Answers1

0

It seems that your main problem is that you aren't seeing the keyboard after calling becomeFirstResponder on your UITextView.

Have you made sure that you're calling it from the main queue?

DispatchQueue.main.async {
    self.textView.becomeFirstResponder()
}
swiftyboi
  • 2,965
  • 4
  • 25
  • 52