首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在不影响消息UIMenuItem的情况下禁用默认UIMenuItem?

如何在不影响消息UIMenuItem的情况下禁用默认UIMenuItem?
EN

Stack Overflow用户
提问于 2017-04-13 09:47:12
回答 2查看 561关注 0票数 0

有一种方法可以禁用默认的UIMenuItem

而不影响消息UIMenuItem?

ViewDidLoad:

代码语言:javascript
复制
JSQMessagesCollectionViewCell.registerMenuAction(#selector(UIResponderStandardEditActions.delete(_:)))
    UIMenuController.shared.menuItems = [UIMenuItem.init(title: "Delete", action: Selector(("delete")))]
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-13 10:28:24

使用

cell.textView.selectable = false in cellForRow方法

票数 0
EN

Stack Overflow用户

发布于 2017-04-16 21:46:32

在这里,您可以选择长时间按messageBubble时会出现的内容。

代码语言:javascript
复制
override func collectionView(_ collectionView: UICollectionView, canPerformAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) -> Bool {

    if (action == #selector(UIResponderStandardEditActions.copy(_:))) {

        if(messages[indexPath.row].isMediaMessage) {
            return false
        } else {
            return true
        }
    }
    if (action == #selector(UIResponderStandardEditActions.cut(_:))) {

        if(messages[indexPath.row].isMediaMessage) {
            return false
        } else {
            return false
        }
    }
    if (action == #selector(UIResponderStandardEditActions.paste(_:))) {

        if(messages[indexPath.row].isMediaMessage) {
            return false
        } else {
            return false
        }
    }

    if (action == #selector(UIResponderStandardEditActions.delete(_:))) {

        if(messages[indexPath.row].isMediaMessage) {
            return true
        } else {
            return true
        }
    }

    return super.canPerformAction(action, withSender: sender)
}

然后在你选择你想要的物品之后会发生什么,

代码语言:javascript
复制
 override func collectionView(_ collectionView: UICollectionView, performAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) {

    if (action == #selector(UIResponderStandardEditActions.delete(_:))) {
        print("deleted")
        print(indexPath.row)

        let messageKey = messages[indexPath.row].keyID

        print("messageKey")
        print(messageKey!)

        messages.remove(at: indexPath.row)
        collectionView.reloadData()
    }
    if (action == #selector(UIResponderStandardEditActions.copy(_:))) {
        // do stuff
    }
}

}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43388885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档