Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

dexter foo
8,233 PointsresignFirstResponder()
In the project file downloads, i noticed there is func called resignFirstResponder() in the IBAction loginButtonPressed under the LoginViewController. Pasan didn't write this function in his video nor did he address the use of it. May i know whats its purpose in the IBAction func loginButtonPressed?
1 Answer

Stepan Ulyanin
11,318 PointsApple reference: Notifies the receiver that it has been asked to relinquish its status as first responder in its window.
Lets say you a making an app where you have a login screen implemented, the user taps on Log In
button and it takes him to another view controller with some text fields (username, password) and then the user will HAVE TO
tap the username field to open the keyboard, which is very uncomfortable for the user to make an extra tap
BUT
you could make the username
textfield to be the first responder
meaning that once the user is taken to the log in screen the text field
will open keyboard automatically as the first object to respond on the screen. Apple reference says: A responder object only becomes the first responder if the current responder can resign first-responder status (canResignFirstResponder) and the new responder can become first responder.
That is why there is such thing like resignFirstResponder()
, hope it helps