how to disable UIMenuControll (cut,copy,paste,select all,delete) in UIviewController subclass?

落爺英雄遲暮 提交于 2019-12-08 13:28:45

问题


i have implemented many methods but paste doesn't hide. i am using Xcode Version 4.5.2

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    UIMenuController *menuController = [UIMenuController sharedMenuController];
    if (menuController) {
        [UIMenuController sharedMenuController].menuVisible = NO;

    }
    return NO;  
}

every method is seems to fail working for me. can anybody help me on this? thanks in advance


回答1:


You need to do these things to enable/disable UIMenuController items.

  1. To show/hide the UIMenuController items, your view or view controller needs to implement canBecomeFirstResponder(returning YES/NO for Show/Hide).

  2. You can also implement the canPerformAction:withSender: method of UIResponder to disable or enable user-interface commands {copy, select, select all, paste and etc} based on the context.

  3. Or you can override the Update method of UIMenuController to handle the custom behavior of an individual item. For example, if the pasteboard holds no data of a compatible type, the Paste command would be disabled. So you may either force to show/hide the paste menu item by overriding this method.




回答2:


You can try this: in your controller's viewDidLoad method, set it to invisible.

[[UIMenuController sharedMenuController] setMenuVisible:NO];

If that does not work, I guess you are out of luck as it is part of the system. The only way I see is to disable the user interaction with objects that might trigger a context menu.



来源:https://stackoverflow.com/questions/16463485/how-to-disable-uimenucontroll-cut-copy-paste-select-all-delete-in-uiviewcontro

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