1

I've been scourging the internet and saw several promising answers but none that worked for me. The problem I have is that I have many ViewControllers that I placed in Storyboard mode.

Lets say in my 5th view controller I have some TextViews and TextFields that pops up a keyboard for user input when pressed. However I want to be able to hide the keyboard when I press the background.

I tried following the first and second responses here: How to dismiss number pad keyboard by tapping anywhere

But I dont think my set up is exactly the same as theirs.

Can someone please help me? Please be VERY SPECIFIC if possible and dont assume I know how to fill in the dots.

Thanks so much!!

edit. sorry for not being clear but I meant I want the app to dismiss the keyboard when the user presses anywhere on the screen (thats not another Text field/view). The link I show does this but my problem is that I am storyboarding so I have multiple UIViewControllers and I'm not sure how to get IBOutlets/IBActions to work for the "secondary" viewcontrollers. They only show up under the first/main one...

Community
  • 1
  • 1
stellarowl12
  • 525
  • 6
  • 18
  • The accepted answer in the question you linked to detects a simple touch on the screen and dismisses the keyboard. What exactly is your setup and how is it different from this (why won't this work for you)? Can you add these details to the question? – lostInTransit May 16 '13 at 06:48
  • hey sorry for not being clear but I meant I want the app to dismiss the keyboard when the user presses anywhere on the screen (thats not another Text field/view). The link I show does this but my problem is that I am storyboarding so I have multiple UIViewControllers and I'm not sure how to get IBOutlets/IBActions to work for the "secondary" viewcontrollers. They only show up under the first/main one... – stellarowl12 May 16 '13 at 18:45

2 Answers2

0

you can use [self.view endEditing:YES];

have a look at the Apple docs for Ending a View Editing Session

Bonnie
  • 4,943
  • 30
  • 34
  • hey sorry for not being clear but I meant I want the app to dismiss the keyboard when the user presses anywhere on the screen (thats not another Text field/view). The link I show does this but my problem is that I am storyboarding so I have multiple UIViewControllers and I'm not sure how to get IBOutlets/IBActions to work for the "secondary" viewcontrollers. They only show up under the first/main one... – stellarowl12 May 16 '13 at 18:52
0

In your application delegate file,

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [self.window endEditing:YES];
}
Hemang
  • 26,840
  • 19
  • 119
  • 186
  • hey sorry for not being clear but I meant I want the app to dismiss the keyboard when the user presses anywhere on the screen (thats not another Text field/view). The link I show does this but my problem is that I am storyboarding so I have multiple UIViewControllers and I'm not sure how to get IBOutlets/IBActions to work for the "secondary" viewcontrollers. They only show up under the first/main one... – stellarowl12 May 16 '13 at 18:46
  • No its fine you'd asked well! Anyways, you can do it by getting touch on your `UIView` and write the same line to dismiss the `UITextField`. – Hemang May 16 '13 at 20:09