如何解决使 UIMenuController 能够在 TextField 中进行复制和粘贴而不使文本字段可编辑 isUserInteractionEnabled = false
我有 textfield.isUserInteractionEnabled = false
的文本字段,但我希望在文本字段中启用复制和粘贴功能,以便用户在其上选择时,它可以打开菜单进行复制,有没有办法做到?
谢谢
解决方法
我用 tableView 找到了解决方案:
func tableView(_ tableView: UITableView,shouldShowMenuForRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView,canPerformAction action: Selector,forRowAt indexPath: IndexPath,withSender sender: Any?) -> Bool {
if (action == #selector(UIResponderStandardEditActions.copy(_:))) {
return true
}
return false
}
func tableView(_ tableView: UITableView,performAction action: Selector,withSender sender: Any?) {
if let cell = tableView.cellForRow(at: indexPath) {
UIPasteboard.general.string = cell.textLabel?.text
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。