How to customize the pop up menu in iPhone?
- by Allen Dang
The application I'm creating needs a function like user selects some text, a pop up menu shows, and user clicks "search" menu to perform a search directly.
Problem is the current pop up menu provided by UIMenuController doesn't support to be extended. So my thought is to subscribe "UIMenuControllerDidShowMenuNotification", get the frame of pop up menu, and display the "search" button right aside.
But during the implementation, I met a strange problem, the notification seems never be sent, means after the menu shown, I still cannot be notified, following are the key section of code.
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(menuDidShow:)
name:UIMenuControllerWillShowMenuNotification
object:nil];
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIMenuControllerDidShowMenuNotification
object:nil];
self.textView = nil;
self.searchBar = nil;
}
- (void)menuDidShow:(NSNotification *)notification {
NSLog(@"menu did show!");
}
The code is too simple to make mistake, can someone help me to understand what's going on? Or what did I miss?