#StackBounty: #ios #objective-c #uikit #uimenucontroller Second UIMenuController not Hiding

Bounty: 50

Tapping the cursor in a UITextView brings up a UIMenuController. Tapping Select causes the relevant text to be selected and another UIMenuController with new options to be displayed. Tapping anywhere else in the text view causes the “second” UIMenuController to hide.

Example of system behavior

I have a custom UIMenuItem that, when tapped, selects the current line of text in a UITextView and then displays the UIMenuController again for subsequent actions, however the “second” UIMenuController does not hide when tapping anywhere else in the view as expected.

Example of undesired behavior

Custom menu item action:

- (void)selectLine:(id)sender {
    NSString *string = [[self textView] text];
    NSRange range = [[self textView] selectedRange];
    NSRange newRange = [string lineRangeForRange:range];

    if ([[string substringWithRange:newRange] hasSuffix:@"n"]) {
        newRange.length -= 1;
    }
    [[self textView] setSelectedRange:newRange];

    CGRect targetRect = [[self textView] firstRectForRange:[[self textView] selectedTextRange]];
    UIMenuController *menuController = [UIMenuController sharedMenuController];
    [menuController setTargetRect:targetRect inView:[self textView]];
    [menuController setMenuVisible:YES animated:YES];
}


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.