I am working on adding custom UIMenuItem
on tableViewCell. I used this stackoverflow post to to add customMenuItem. This worked fine on ios 6. But it is not at all working on ios 7.
Below is the implementation I have:
In viewDidLoad
:
UIMenuItem *sendByEmailMenuItem = [[UIMenuItem alloc] initWithTitle:@"Send By Email" action:@selector(sendByEmail:)];
[[UIMenuController sharedMenuController] setMenuItems: @[sendByEmailMenuItem]];
[[UIMenuController sharedMenuController] update];
Then adding its delegate
// Shared Menu item delegate actions
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
self.orderAtIndex = [self.orders objectAtIndex:indexPath.row];
[self becomeFirstResponder];
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
return (action == @selector(sendByEmail:));
}
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
if (action == @selector(sendByEmail:)) {
[self sendByEmail:sender];
}
}
// Subclassing Table View cells
-(BOOL) canPerformAction:(SEL)action withSender:(id)sender {
return (action == @selector(sendByEmail:));
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void) sendByEmail: (id) sender {
// Some actions...
}
What I am doing wrong? Any help is appreciated. Thanks
In viewWillAppear
or viewDidLoad
, i added these
UIMenuItem *translateToMenu = [[UIMenuItem alloc] initWithTitle:@"Translate to.." action:@selector(translateTo:)];
UIMenuController *menuController = [UIMenuController sharedMenuController];
[menuController setMenuItems:[NSArray arrayWithObject:translateToMenu]];
[menuController setMenuVisible:YES animated:YES];
added this method
-(void) translateTo: (id) sender {}
and add only these 2 methods
- (BOOL) canPerformAction:(SEL)selector withSender:(id) sender {
if (selector == @selector(translateTo:))
return YES;
else
return NO;
}
- (BOOL) canBecomeFirstResponder {
return YES;
}
Try this and let me know…
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.