When i touch a label UIMenuController
appears with my custom list of items, and that works well. But when UIMenuController
appear in a standard UISearchBar
i see all my custom items there too. Why?
I need to show only standard (copy, paste) items for standard UISearchBar and custom items when i touch the label. Can you explain how should i do that?
UPDATE
What i did (not good solution):
If we have keyboard, that is searchbar, if we don't, that is label.
Flag, which mean which items list i will use
BOOL standardList;
Register for keyboard appear/disappear
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
[super viewWillDisappear:animated];
}
-(void)keyboardWillShow:(id)sender
{
standardList = YES;
}
-(void)keyboardWillHide:(id)sender
{
standardList = NO;
}
And check flag, in next method:
- (BOOL) canPerformAction:(SEL)selector withSender:(id) sender
{
if (selector == @selector(copy:))
{
return YES;
}
if (!standardList)
{
if ((selector == @selector(makeCall:)) || (selector == @selector(createNewContact:)))
{
return YES;
}
}
return NO;
}
That work well, BUT: iPad keyboard have "hide keyboard" button, and keyboard can hide without [UISearchBar resingFirstResponder]
.
Even if i add next lines:
-(void)keyboardWillHide:(id)sender
{
standardList = NO;
[mySearchController setActive:NO];
}
that's still bad solution - i can't hide keyboard while searching and scroll search results.
Any suggestions?