问题
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.
To show/hide the UIMenuController items, your view or view controller needs to implement
canBecomeFirstResponder
(returning YES/NO for Show/Hide).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.Or you can override the
Update
method ofUIMenuController
to handle the custom behavior of an individual item. For example, if the pasteboard holds no data of a compatible type, thePaste
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