【问题标题】:How to add custom menu options for chat bubbles - JsqMessage如何为聊天气泡添加自定义菜单选项 - JsqMessage
【发布时间】:2018-02-01 15:40:02
【问题描述】:

我正在将 JSQMessage 用于聊天应用程序。长按我可以 显示默认菜单选项(复制和删除)

现在的挑战是在菜单中添加另一个选项。任何帮助都会 赞赏。

默认菜单选项的代码是

override func collectionView(_ collectionView: UICollectionView, shouldShowMenuForItemAt indexPath: IndexPath) -> Bool {
    super.collectionView(collectionView, shouldShowMenuForItemAt: indexPath)
    return true;
}

override func collectionView(_ collectionView: UICollectionView, canPerformAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) -> Bool {

    let message = messageList[indexPath.item]
    switch action.description {
    case quickChatOptionDelete:
    // you can only delete your sent messages
    if message.senderId == strMemberID {
        return true
    } else {
        return false
    }
    case quickChatOptionCopy:
        return true
    case quickChatOptionUserList:
        return true
    default:
        return false
    }
}
    override func collectionView(_ collectionView: UICollectionView, performAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) {

    let message = messageList[indexPath.item]

    switch action.description {
    case quickChatOptionDelete:
        if message.senderId == strMemberID {
            deleteMessage(messageId:message.messageId!)
        }
        break

    case quickChatOptionCopy: break
    case quickChatOptionUserList:
        print("list")
        break
    default: break
        // do nothing
    }
}

【问题讨论】:

    标签: ios iphone swift chat jsqmessagesviewcontroller


    【解决方案1】:

    我相信你想看看UIMenuController.shared.menuItems 属性。您可以像这样设置菜单项:

    let items = [
            UIMenuItem(
                title: "Copy",
                action: copyTextAction),
            UIMenuItem(
                title: "First Name",
                action: firstName),
            UIMenuItem(
                title: "Last Name",
                 action: lastName),
            UIMenuItem(
                title: "Email",
                action: email),
            UIMenuItem(
                title: "Home Phone",
                action: homePhone),
            UIMenuItem(
                title: "Mobile Phone",
                action: mobilePhone),
            UIMenuItem(
                title: "Street Address",
                action: streetAddress),
            UIMenuItem(
                title: "City",
                action: city),
            UIMenuItem(
                title: "State",
                action: state),
            UIMenuItem(
                title: "Zip",
                action: zip)
        ]
        UIMenuController.shared.menuItems = items
    

    【讨论】:

      猜你喜欢
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多