-2

I have a ViewController specifically for making a comment, it opens when "Comment" button is pressed in MainVC and only contains a UITextView.

User has to click on the UITextView for the keyboard to appear to start typing.

Is it possible to make the UITextView selected by default when entering the view?

  • just search, google you have plenty of questions about that http://stackoverflow.com/questions/987975/how-do-i-give-a-uitextview-focus-programmatically – Lu_ Apr 04 '17 at 07:05

3 Answers3

0

This should do the trick (put it inside e.g. viewDidLoad())

yourTextView.becomeFirstResponder()
0

In you viewWillAppear method of comment viewController

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated) 
    textview.becomeFirstResponder()
}

so whenever your viewController will be appearing the keyboard will appear as textview becomes active responder.

Jagdeep
  • 1,158
  • 11
  • 16
0

There is an one method becomeFirstResponder() that will help you to focus in UIKit like textField.

Put this method in viewDidAppear() or viewDidLoad()

override func viewDidLoad() {
        super.viewDidLoad()
        txtcheck.becomeFirstResponder()

    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        txtcheck.becomeFirstResponder()
    }
Sakir Sherasiya
  • 1,562
  • 1
  • 17
  • 31