问题
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?
回答1:
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.
回答2:
This is resolved in iOS 5 (rdar://problem/8819322).
来源:https://stackoverflow.com/questions/4598456/updating-uimenucontroller-on-the-fly