Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble Displaying UIMenuController When Cell Tapped In UITableView
    primarykey
    data
    text
    <p>I'm trying to display a custom UIMenuController when a User long presses on a cell in a grouped UITableView. However, I can't seem to get the UIMenuController to display after successfully detecting the long press. Any help is greatly appreciated. </p> <pre><code>MyViewController.h @interface MyViewController : UIViewController &lt;UITableViewDelegate,UITableViewDataSource&gt; UITableView *table; @property (nonatomic, retain) IBOutlet UITableView *table; @end </code></pre> <p>In the cellForRowAtIndexPath I attach my Long Press Gesture Recognizer</p> <pre><code>cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SectionsTableIdentifier] autorelease]; UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; [cell addGestureRecognizer:longPress]; [longPress release]; </code></pre> <p>Here is my handleLongPress action method</p> <pre><code>-(void)handleLongPress:(UIGestureRecognizer *)longPress { if (longPress.state == UIGestureRecognizerStateBegan) { CGPoint pressLocation = [longPress locationInView:self.table]; NSIndexPath *pressedIndexPath = [self.table indexPathForRowAtPoint:pressLocation]; UIMenuItem *first = [[UIMenuItem alloc] initWithTitle:@"Save" action:@selector(saveRecent)]; UIMenuItem *second = [[UIMenuItem alloc] initWithTitle:@"Edit" action:@selector(editQuery)]; UIMenuController *menuController = [UIMenuController sharedMenuController]; menuController.menuItems = [NSArray arrayWithObjects:first,second,nil]; [menuController setTargetRect:longPress.view.frame inView:longPress.view.superview]; [menuController setMenuVisible:YES animated:YES]; [pressedIndexPath release]; } } </code></pre> <p>The Action methods for the Edit and Save just display a UIAlertView. I also implemented the below method to ensure that when the UIMenuController is displayed only Save and Edit options will be present</p> <pre><code>-(BOOL)canPerformAction:(SEL)action withSender:(id)sender { BOOL canPerform = NO; if (action == @selector(saveRecent)) { canPerform = YES; } if (action == @selector(editQuery)) { canPerform = YES; } return canPerform; } </code></pre> <p>I'm also claiming MyViewController to be first responder</p> <pre><code>-(BOOL)canBecomeFirstResponder { return YES; } </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.
    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