jtbandes
jtbandes

Reputation: 118691

Updating UIMenuController on the fly

My application has the ability to pop up a menu. When the "Select All" button is pressed, I want to enable the "Delete" button. However I haven't been able to get this working.

Here is a sample project illustrating the issue. Run it, then tap the Menu button, press Select All. The Delete button should appear immediately, but it only appears when you hide the menu and then show it again. How can I fix this?

Upvotes: 1

Views: 984

Answers (2)

jtbandes
jtbandes

Reputation: 118691

This is resolved in iOS 5 (rdar://problem/8819322).

Upvotes: 0

Felix
Felix

Reputation: 35384

The following does the trick:

- (void)didHide:(NSNotification *)notif {
    UIMenuController *mc = [UIMenuController sharedMenuController];
    dispatch_async(dispatch_get_global_queue(0,0), ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            [mc update];
            [mc setMenuVisible:YES animated:YES];
        });
    });
}

I've noticed however that it does not work very reliable, for example when setting animated to NO, the menu is not updated on the fly.

Upvotes: 2

Related Questions