Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have just recently open sourced <a href="https://github.com/Stunner/SATextField" rel="nofollow">a project on Github</a> that should make this all relatively easy to do. It includes a class that can be easily inserted into a cell and a sample project demonstrating its capabilities.</p> <p>If you look in RootTableViewController's <code>viewDidLoadMethod</code> you will see that I am adding a gesture recognizer:</p> <pre><code> self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)]; _tapGestureRecognizer.delegate = self; _tapGestureRecognizer.cancelsTouchesInView = NO; [self.tableView addGestureRecognizer:_tapGestureRecognizer]; </code></pre> <p>Add the dismiss keyboard method:</p> <pre><code> - (void)dismissKeyboard { [_textField resignFirstResponder]; } </code></pre> <p>Add a gesture recognizer callback (in RootTableViewController):</p> <pre><code>//see: http://stackoverflow.com/questions/7195661/why-is-uigesturerecognizer-being-called-on-my-textfield-clear-button - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if([touch.view isKindOfClass:[UITextField class]] || [touch.view isKindOfClass:[UIButton class]]) { return NO; } return YES; } </code></pre> <p>Of course, this means you have to make RootTableViewController adhere to the UIGestureRecognizerDelegate protocol (in the header file):</p> <pre><code>@interface RootTableViewController : UITableViewController&lt;SATextFieldDelegate, UIGestureRecognizerDelegate&gt; </code></pre> <p>If you want the user to scroll the table view and dismiss the keyboard implement the following table view delegate callback:</p> <pre><code>- (void)scrollViewWillBeginDragging:(UIScrollView *)activeScrollView { if (_textField.isFirstResponder) { [self dismissKeyboard]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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