简体   繁体   English

iOS 7-自定义UIMenuItem在TableViewCell上不起作用

[英]ios 7 - Custom UIMenuItem not working on TableViewCell

I am working on adding custom UIMenuItem on tableViewCell. 我正在UIMenuItem在tableViewCell上添加自定义UIMenuItem I used this stackoverflow post to to add customMenuItem. 我使用了这个stackoverflow 帖子来添加customMenuItem。 This worked fine on ios 6. But it is not at all working on ios 7. 这在ios 6上工作正常,但在ios 7上却根本不工作。

Below is the implementation I have: 下面是我的实现:

In viewDidLoad : 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 viewWillAppearviewDidLoad ,我添加了这些

 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… 试试这个,让我知道...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM