Search code examples
iphoneipadxcode4uitextviewuimenucontroller

no uimenucontroller with uitextview showing, universal app xcode 4


On the simulator I see the UIMenucontroller without a problem but it won't appear testing on device running iOs 4+ . It is a standard uitextview added using IB.

I have added these methods to the viewcontroller which is the delegate but I don't think they are necessary since I want the standard menucontroller, select, copy, etc. Not to mention they are not being called.

thanks for the help

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {

    NSLog(@"Can perform action called");

    BOOL answer = NO;

    if (action == @selector(copy:))
    {
        answer = YES;
    }
    if (action == @selector(cut:))
    {
        answer = YES;     
    }
    if (action == @selector(paste:))
    {
        answer = YES;
    }
    if (action == @selector(select:))
    {
        answer = YES;
    }
   if (action == @selector(selectAll:))
    {
        answer = YES;
    }

    return answer;
}

- (BOOL) canBecomeFirstResponder {
    NSLog(@"can become first called");
    return YES;
}

Solution

  • You need to add a gesture recognizer, or override the touchesEnded:withEvent: method, and display the menu controller:

    //Assumes you assigned a CGRect for where the menu should appear to theRect
    UIMenuController *mc = [UIMenuController sharedMenuController];
    [mc setTargetRect:theRect inView:self];
    [mc setMenuVisible:YES animated:YES];
    

    You also should override the methods -copy,-cut,-paste, etc.