我试图UIMenuController
在用户选择表中的任何行时显示。我UITableViewController
用来显示带有自定义单元格的表格。
我的代码:-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// [tableView deselectRowAtIndexPath:indexPath animated:NO];
MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath];
CGRect cellFrame = cell.frame;
[self.view becomeFirstResponder];
UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Item1" action:@selector(action1:)];
UIMenuItem *menuItem1 = [[UIMenuItem alloc] initWithTitle:@"Item2" action:@selector(action2:)];
UIMenuItem *menuItem2 = [[UIMenuItem alloc] initWithTitle:@"Item3" action:@selector(action3:)];
UIMenuController * menuController = [UIMenuController sharedMenuController];
menuController.menuItems = [NSArray arrayWithObjects:menuItem, menuItem1, menuItem2, nil];
menuController.arrowDirection = UIMenuControllerArrowDown;
[menuController setTargetRect:cellFrame inView:self.view];
[menuController setMenuVisible:YES animated:YES];
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
但UIMenuController
没有显示。上面的代码有什么问题?
另外,我参考了这些链接。但没有运气。