我有一个气球视图,当我点击单元格时 UIMenuController 没有出现。我试图在
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath,
然后我添加了一个长按手势
- (void)longPress:(UILongPressGestureRecognizer *)recognizer,
最后我在扩展中添加了一个实现
UITableViewCell
课,但它仍然不起作用。
这是一个例子
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL) canPerformAction:(SEL)selector withSender:(id) sender
{
return YES;
}
-(void)copyAction:(id)sender{
NSLog(@"copy");
}
-(void)deleteAction:(id)sender{
NSLog(@"delete");
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
BalloonCell *cell = (BalloonCell*)[tableView cellForRowAtIndexPath:indexPath];
[self becomeFirstResponder];
BOOL isCanBecomde = [self canBecomeFirstResponder];
BOOL isFirst = [self isFirstResponder];
UIMenuItem *copy = [[UIMenuItem alloc] initWithTitle:@"Копировать" action:@selector(copyAction:)];
UIMenuItem *delete = [[UIMenuItem alloc] initWithTitle:@"Удалить" action:@selector(deleteAction:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
CGRect drawRect = [cell convertRect:cell.bounds toView:self.view];
[menu setTargetRect:drawRect inView:window];
[menu setMenuItems:[NSArray arrayWithObjects:copy, delete, nil]];
[menu setMenuVisible:YES animated:YES];
}
你有任何猜测为什么 UIMenuController 没有出现吗?