How to disable context menu for UISearchBar

I need to disable the context menu displayed in the UISearchBar

Currently, I have tried to subclass UISearchBar and override canPerformAction: withSender: as shown below, but without success. What is the best way to do the same?

Header file:

#import <UIKit/UIKit.h>

@interface CustomSearchBar : UISearchBar

@end

And implementation

#import "CustomSearchBar.h"

@implementation CustomSearchBar

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    return NO;
}

@end
+5
source share

All Articles