objective-c - 从 UITableView 中的 UITextView 复制文本
问题描述
我有一个表格视图单元格,它有一个图像视图、一个 UILabel 和一个 TextView。我希望用户在长按 TextView 时能够从 TextView 中选择文本。
我为单元格创建了一个手势识别器,当用户长按单元格时,手势识别器被调用,但我没有菜单或光标让用户能够选择文本然后复制它. 下面是将长按附加到 UITableView 单元格的代码
UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressgesture:)];
[tableView addGestureRecognizer:longPressRecognizer];
我也有以下代码被调用
- (void)LongPressgesture:(UILongPressGestureRecognizer *)gesture{
if (gesture.state == UIGestureRecognizerStateEnded) {
NSLog(@"Long press Ended .................");
}
else {
NSLog(@"Long press detected .....................");
}
}
该函数被调用,所以我在输出日志上看到消息“检测到长按”,但我没有得到复制文本的菜单。我尝试在长按部分创建一个菜单,如下所示:
UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyText:)];
UIMenuController *menuCont = [UIMenuController sharedMenuController];
[menuCont setTargetRect:CGRectMake(10, 100, 400, 400) inView:tableview];
menuCont.arrowDirection = UIMenuControllerArrowDown;
menuCont.menuItems = [NSArray arrayWithObject:menuItem];
[menuCont setMenuVisible:YES animated:YES];
但是没有调用复制文本功能,也没有菜单。
谢谢!
解决方案
推荐阅读
- java - 使用 Reactive Spring 和 WebFlux 将数据推送到 websocket
- r - 如何切换我的列和行,同时保持观察值分配给它们各自的值?
- python - 多个进程同时运行时间
- excel - 如何为 Dimmed 变量建立第三个变量
- c# - 使用 File.Copy 时访问被拒绝
- sql - PostgresSQL 无法按 json_build_object 结果排序(从子查询获得)
- c - 实现条目超时的 C 哈希表的最有效方法是什么?
- c++ - 用于 stm32cube IDE 的 TLC5940 软件库
- c# - Azure IotHubException 在尝试接收消息时出现“连接已关闭,因为另一个 AMQP 客户端打开了接收链接”
- sharepoint - Spfx 扩展自定义操作组件 ID 由查询参数指定,但找不到匹配的清单