在我的應用程序中,我必須顯示一個菜單控制器,用於點擊表格視圖單元格。它顯示一個菜單。以及所有的行動正在成功執行。很好,直到現在。
我面臨的一個小問題是,如果再次點擊單元格(或其他單元格),我無法隱藏菜單控制器。這裏是我正在使用的代碼:iOS - 在UITableViewCell中顯示菜單
- (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];
}
}
我不知道爲什麼它沒有隱藏在再次點擊表格視圖單元格。有人能指導我做什麼錯誤嗎?
你試過'[self resignFirstResponder];'而不是'setMenuVisible:NO' ... – jjv360 2013-03-11 11:14:01
我注意到的問題是,代碼行「if([menuController isMenuVisible])」總是返回NO。 – Satyam 2013-03-11 11:53:03