Emulating backgroundTap in Monotouch to hide keyboard

I searched and searched, and couldn’t figure out how to hide the keyboard when a user clicks on the view…

Finally, I dun figured it out on my own. It probably should be obvious to most, but here it is anyhow (place this in the code for your view controller):

public override void TouchesEnded (NSSet touches, UIEvent evt)
{
	foreach (var item in this) {
		var tf = item as UITextField;
		if (tf != null && tf.IsFirstResponder) {
			tf.ResignFirstResponder ();
		}
	}
	base.TouchesEnded (touches, evt);
}
Advertisements

One thought on “Emulating backgroundTap in Monotouch to hide keyboard

  1. Shane says:

    thanks dude. worked great. not obivous. smart. thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: