I have several objects inheriting UIViewin my application that track branches to them and present a Copy / Paste popup if they contain some specific data. When a popup is displayed, I also change the appearance of the object.
Here's how it is implemented:
- (void)viewDidReceiveSingleTap:(NSNotification *)n {
MyObject *mo = (MyObject *)n.object;
[mo becomeFirstResponder];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu update];
[menu setTargetRect:CGRectMake(...) inView:mo];
[menu setMenuVisible:YES animated:YES];
}
MyObjectthe class, in turn, defines canBecomeFirstResponder:and canResignFirstResponder:as always returns YES. becomeFirstResponder:, resignFirstResponder:and are canPerformAction:withSender:also defined accordingly (here I change the appearance of the object).
Here's what went wrong:
I click object 1. The method viewDidReceiveSingleTap:above is called , and the object canBecomeFirstResponder:and is becomeFirstResponder:also called. A popup menu is displayed as expected.
2. viewDidReceiveSingleTap: , . -, canResignFirstResponder:, resignFirstResponder: 1 , , . canBecomeFirstResponder: becomeFirstResponder: 2 , . ( viewDidReceiveSingleTap: setMenuVisible:YES). , 2 ( ) - , 2 , , .
? ?