Your question:
How can I set custom UIMenuController only for the UITableView and not for UITextView? I want the default options alone in the UITextView.
The answer is: You can't.
Reason: You can only get the UIMenuController Instance by invoking class method like this:[UIMenuController sharedMenuController]
. See Apple's documentation:UIMenuController
How to solve the issue:
Set your custom UIMenuItems nil When shared UIMenuController will hide.
Example code:
-(void)longPress:(UILongPressGestureRecognizer*)gesture {
//other stuff code...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMenuWillShowNotification:) name:UIMenuControllerWillShowMenuNotification object:nil];
}
-(void)handleMenuWillShowNotification:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIMenuControllerWillShowMenuNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMenuWillHideNotification:) name:UIMenuControllerWillHideMenuNotification object:nil];
}
-(void)handleMenuWillHideNotification:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIMenuControllerWillHideMenuNotification object:nil];
UIMenuController *menuController = notification.object;
[menuController setMenuItems:nil];
}