Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I solved this dilemma by subclassing UITextView to provide a way to override the nextResponder and disable the built-in actions (Paste), like so:</p> <pre><code>@interface CustomResponderTextView : UITextView @property (nonatomic, weak) UIResponder *overrideNextResponder; @end </code></pre> <hr> <pre><code>@implementation CustomResponderTextView @synthesize overrideNextResponder; - (UIResponder *)nextResponder { if (overrideNextResponder != nil) return overrideNextResponder; else return [super nextResponder]; } - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (overrideNextResponder != nil) return NO; else return [super canPerformAction:action withSender:sender]; } @end </code></pre> <p>Then, in your gesture action handler, check whether the text view is already the first responder. If so, have it override the next responder; otherwise the keyboard is probably hidden anyway and you can simply <code>becomeFirstResponder</code>. You'll also have to reset the override when the menu hides:</p> <pre><code>if ([inputView isFirstResponder]) { inputView.overrideNextResponder = self; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuDidHide:) name:UIMenuControllerDidHideMenuNotification object:nil]; } else { [self becomeFirstResponder]; } - (void)menuDidHide:(NSNotification*)notification { inputView.overrideNextResponder = nil; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIMenuControllerDidHideMenuNotification object:nil]; } </code></pre> <p>Using the table view delegate methods introduced in iOS 5 (<code>shouldShowMenuForRowAtIndexPath</code> etc.) wasn't a solution for me as I needed control over the positioning of the menu (by default it's simply horizontally centered over the cell, but I'm displaying message bubbles and wanted the menu centered over the actual bubble).</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