Updating UIMenuController on the fly

人盡茶涼 提交于 2019-12-11 08:08:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!