-1

I am using JSQMessage for a chat application. On long press i am able to display default menu options (Copy & Delete)

enter image description here

Now the challenge is to add another option in menu. Any help will be appreciated.

Code for the default menu option is

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
    }
}
aqsa arshad
  • 801
  • 8
  • 27

1 Answers1

0

I believe you want to look at the UIMenuController.shared.menuItems property. You can set the menu items like this:

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