Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had to implement a similar UX for my UITableView (inside which appears a UITextField). First, add a <code>UITapGestureRecognizer</code> to the tableView. This will begin to catch all the taps that occur from now on.</p> <pre><code>UITapGestureRecognizer* tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; [self.tableView addGestureRecognizer:tapGestureRecognizer]; [tapGestureRecognizer release]; </code></pre> <p>The side-effect is however, that you do not want to dismiss the keyboard when the user taps on the UITextField itself. So, this case has to be distinguished.</p> <p>The handleTap method implementation looks something like-</p> <pre><code>/* In the text editing mode, listens to all taps occurring on the table view to exit the mode. There are two special cases to consider: a) Text field's clear button b) Text field */ -(void)handleTap:(UITapGestureRecognizer*)tapRecognizer { if(tapRecognizer.state == UIGestureRecognizerStateEnded) { //Figure out where the user tapped CGPoint p = [tapRecognizer locationInView:textField]; CGRect textFieldBounds = textField.bounds; CGRect clearButtonBounds = CGRectMake(textFieldBounds.origin.x + textFieldBounds.size.width - 44, textFieldBounds.origin.y, 44, textFieldBounds.size.height); if(CGRectContainsPoint(clearButtonBounds, p)) textField.text = @""; if(CGRectContainsPoint(textFieldBounds, p)) return; [textField resignFirstResponder]; //remove the tap gesture recognizer that was added. for(id element in self.tableView.gestureRecognizers) { if([element isKindOfClass:[UITapGestureRecognizer class]]) { [self.tableView removeGestureRecognizer:element]; } } } [self commitNewText]; } } </code></pre> <p>HTH. Mark it as the answer if you like it.</p> <p>-Akshay</p>
    singulars
    1. This table or related slice is empty.
    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.
    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