我正在尝试将UIMenuControl弹出窗口置于用户选择的任何单元格之上....
目前我有以下代码,它总是将UIMenuControl放在iPhone的屏幕中间......
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self becomeFirstResponder];
UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"View" action:@selector(viewListing:)];
UIMenuItem *menuItem1 = [[UIMenuItem alloc] initWithTitle:@"Edit" action:@selector(editListing:)];
UIMenuItem *menuItem2 = [[UIMenuItem alloc] initWithTitle:@"Call" action:@selector(callListing:)];
UIMenuItem *menuItem3 = [[UIMenuItem alloc] initWithTitle:@"Open Houses" action:@selector(openHouses:)];
UIMenuController *menuController = [UIMenuController sharedMenuController];
[menuController setTargetRect:CGRectMake(0, 205, 320, 200) inView:self.view];
menuController.menuItems = [NSArray arrayWithObjects:menuItem, menuItem1, menuItem2, menuItem3, nil];
menuController.arrowDirection = UIMenuControllerArrowDown;
[menuController setMenuVisible:YES animated:YES];
}
任何帮助都会非常感激。
答案 0 :(得分:1)
很明显,您的菜单始终位于中心位置:您正在对坐标进行硬编码。
<强>解决方案强>:
首先必须计算单元格的位置。然后从中计算targetRect
帧。
提示:您可以使用rectForRowAtIndexPath:
获取单元格的框架。