Skip to content

Instantly share code, notes, and snippets.

@xareelee
Last active August 29, 2015 14:26
Show Gist options
  • Save xareelee/19e9393a633b93e037f4 to your computer and use it in GitHub Desktop.
Save xareelee/19e9393a633b93e037f4 to your computer and use it in GitHub Desktop.
Dismiss keyboard when tapping table view (or content view) using ReactiveCocoa
- (void)viewDidLoad
{
  [super viewDidLoad];
  @weakify(self);
  
  // Add a gesture recognizer to a view
  UITapGestureRecognizer *tap = [UITapGestureRecognizer new];
  [tap.rac_gestureSignal subscribeNext:^(id x) {
    @strongify(self);
    [self.tableView endEditing:YES];  // This will dismiss the keyboard
  }];
  tap.cancelsTouchesInView = NO;
  [self.tableView addGestureRecognizer:tap];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment