我正在制作一个类似于手机上的 Messages 应用程序的 iphone 应用程序。我刚刚设置了通过 UIMenuController 复制消息的能力,但是如果键盘正在显示并且有人试图复制消息,键盘就会消失(可能是因为我[cell becomeFirstResponder];
在哪里cell
复制了消息单元格)。
有没有办法在不丢失键盘的情况下显示复制消息?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
//...other cell setup stuff...
UILongPressGestureRecognizer *longPressGesture =
[[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(showCopyDialog:)];
[cell addGestureRecognizer:longPressGesture];
return cell;
}
- (void)showCopyDialog:(UILongPressGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan)
{
ConvoMessageCell *cell = (ConvoMessageCell *)[gesture view];
NSIndexPath *indexPath = [self.tblConvo indexPathForCell:cell];
UIMenuController *theMenu = [UIMenuController sharedMenuController];
[cell becomeFirstResponder];
[theMenu setTargetRect:CGRectMake(menuX, menuY, 100, 100) inView:cell];
[theMenu setMenuVisible:YES animated:YES];
}
}