我正在制作一个类似于手机上的Messages应用程序的iphone应用程序。我只是设置了通过UIMenuController复制邮件的功能,但是如果键盘显示并且有人试图复制邮件,键盘就会消失(大概是因为我的[cell becomeFirstResponder];
,其中cell
是被复制的邮件单元格)。显示UIMenuController丢失键盘
有没有办法显示复制信息而不会丢失键盘?
- (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];
}
}
这可能工作,但MenuController将被放置在单元格的水平中心。 –