Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Make sure you have set your object to process those touch events:</p> <pre><code>[myButton addTarget:self action:@selector(buttonTouch:withEvent:) forControlEvents:UIControlEventTouchUpInside]; </code></pre> <p>And then process the touch event in the method you declared:</p> <pre><code>- (IBAction) buttonTouch:(id) sender withEvent:(UIEvent *) event </code></pre> <p>Updated for UIView (Assuming you already have an outlet created and wired up):</p> <pre><code>[myView addTarget:self action:@selector(myTouchEvent:withEvent:) forControlEvents:UIControlEventTouchUpInside]; </code></pre> <p>And then:</p> <pre><code>- (IBAction) myTouchEvent:(id) sender withEvent:(UIEvent *) event </code></pre> <p>Now that I understand what you are trying to do (dismiss the keyboard when touching outside the textbox), there is a simple solution that works well with almost every scenario).</p> <p>Step 1 - Create a button that is sized the same as the View that the TableViewController is placed in. (large button). Step 2 - Send that button to the back (Editor->Arrange->Send to Back) Step 3 - Wire up an IBAction to that button and call it dismissKeyboardButtonPressed (hint if you are not already using the assistant editor, you should be) Step 4 - Inside the IBAction method put (assuming your TextField is called myTextField):</p> <pre><code>[myTextField resignFirstResponder]; </code></pre> <p>Step 5 - Run it. Whenever you touch anywhere in the view outside of the textbox, it will dismiss the keyboard.</p> <p>This is the method I use almost anytime I put a TextField on a view, and need to dismiss the KB when touching outside the TextField.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload