In my application, i've to show a menu controller on tapping a table view cell. Its showing a menu. As well as all the actions are being executed successfully. Good till now.
One minor problem I'm facing is that, I'm not able to hide the menu controller if the cell (or some other cell) is tapped again. Here's the code that I'm using:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UIMenuController* menuController = [UIMenuController sharedMenuController];
if ([menuController isMenuVisible])
{
[menuController setMenuVisible:NO animated:YES];
}
else
{
[self becomeFirstResponder];
self.selectedIndex = indexPath.row;
[menuController setTargetRect:[tableView rectForRowAtIndexPath:indexPath] inView:tableView];
[menuController setMenuItems:@[
[[UIMenuItem alloc] initWithTitle:@"Play" action:@selector(playVideo:)],
[[UIMenuItem alloc] initWithTitle:@"Edit" action:@selector(editVideo:)],
[[UIMenuItem alloc] initWithTitle:@"Delete" action:@selector(deleteVideo:)],
[[UIMenuItem alloc] initWithTitle:@"Share" action:@selector(shareVideo:)],
[[UIMenuItem alloc] initWithTitle:@"Cancel" action:@selector(cancelMenu:)]
]];
menuController.arrowDirection = UIMenuControllerArrowUp;
[menuController setMenuVisible:YES animated:YES];
}
}
I don't know why is it not hiding on tapping the table view cell again. Can some one guide me on what's the mistake that I'm doing?