UIMenuController didDismiss方法?

时间:2013-01-30 15:32:55

标签: ios4 uitableview ios5 uimenucontroller

我有UITableView有一个didSelectRow方法......它会创建一个UIMenuController并显示它。

目前,它可以正常工作但是当UIMenuController解雇时我想调用[tableView1 deselectRowAtIndexPath:path1 animated:YES];

NSIndexPath *path1;
UITableView *table1;
#pragma maek - Table View
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    path1 = indexPath;

    tablview1 = tableview;

        CGRect location = [tableView rectForRowAtIndexPath:indexPath];

    location.origin.y = location.origin.y+30;

    [self becomeFirstResponder];

    UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"View Item" action:@selector(viewItem:)];
    UIMenuItem *menuItem1 = [[UIMenuItem alloc] initWithTitle:@"Edit Item" action:@selector(editItem:)];
    UIMenuItem *menuItem3 = [[UIMenuItem alloc] initWithTitle:@"Cancel" action:@selector(cancelSubMenu:)];

    UIMenuController *menuController = [UIMenuController sharedMenuController];
    [menuController setTargetRect:location inView:self.view];
    menuController.menuItems = [NSArray arrayWithObjects:menuItem, menuItem1,menuItem3, nil];

    menuController.arrowDirection = UIMenuControllerArrowUp;

    [menuController setMenuVisible:YES animated:YES];
}

-(IBAction)cancelSubMenu:(id)sender 
{
    [tableView1 deselectRowAtIndexPath:path1 animated:YES]; 
}

-(BOOL)canBecomeFirstResponder 
{
    return YES; 
}

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{
    if(action == @selector(viewItem:)){return YES;}
    if(action == @selector(editItem:)){return YES;}
    if(action == @selector(cancelSubMenu:)){return YES;}

    return NO; 
}

当用户点击UIMenuController上的取消按钮时,该行被正确取消选择。但是,当用户点击屏幕上的任何其他位置时,UIMenuControlller会解散,但仍然会选中该行。

是否有某种didDismiss UIMenuController方法?

1 个答案:

答案 0 :(得分:2)

UIMenuController会在隐藏名为UIMenuControllerDidHideMenuNotification之后发布通知,您可以订阅此通知以调用方法,该方法又会在您的表格视图中调用deselectRowAtIndexPath。例如:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourMethodHere) name:UIMenuControllerDidHideMenuNotification object:nil];