tags:

views:

84

answers:

2

I have a UITextView in my Navbar that is acting as a search box. I would like to dismiss the associated keyboard when the user taps below the text box - namely on the MKMapView. However I can't figure out how to do this since it doesn't look like I can intercept touches from the mapview.

I have looked at a number of solutions, but none seem to work for my case as far as I can tell. Does anyone have a simple way to do this? I am a bit of a noob, so please let me know if I am not providing some relevant information, and please provide a few lines of example code in your answer if you can - I am still a bit shaky with terminology. Thanks!

screenshot

+1  A: 

Assuming

UITextView *textView; 

Then you can dismiss the keyBoard by sending:

[textView resignFirstResponder];

Also: you may prefer to use a UISearchBar and set it as the navigationItem.titleViewof the ViewController. This offers some nice delegate methods.

Felix
Thanks for the tip on using a UISearchBar. I will try that. My problem is that I'm not sure how to detect when the user clicks the mapview, so I have nowhere to write that line of code :)
Imran
In have added code for getting the touches.
Felix
I don't think you can do this! See: http://stackoverflow.com/questions/1049889/how-to-intercept-touches-events-on-a-mkmapview-or-uiwebview-objects. Let me know if I am misunderstanding. I am looking into overlaying a transparent view over the map when the keyboard is up and getting touches from that (the accepted solution in my link looks overly complex for my purposes).
Imran
You seem to be right. A transparent view seems to be a good idea. You should probably also forward all touch events from that view to the mapview. (I removed my wrong code)
Felix
OK, great. Things are coming into focus now. Thanks for all the help.
Imran