Simple question: how can I resign my textfield if my “done” key is Search. Essentially, what do I do if the user does not want to search, but instead wants to cancel…
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use: a cancel button for SearchBar and need to implement this
SearchBar delegate:This is a proper way to resign the responder if user doesn’t want to search.
Look at how you can add an in-built Cancel button in UISearchBar. Check the property “Shows Cancel Button” (Red Arrow highlight)
EDIT:
STEP-1:
Check conditionally whether your textField’s text is blank? If so resignFirstResponder for the TextField. You need to set the Delegate to
selffor the UITextField using code:Or you can do the same from the interface builder by connecting TextField’s
delegatetoFile's Owner.STEP-2: You need to implement this delegate method.
EDIT-1:
Now create a UIToolbar with one bar button labeled ‘Cancel’
Once you have done that:
You can write an button click event for UIToolBar:
Once you have done that you can now just write:
Hope this helps you.