我正在使用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
}
}
答案 0 :(得分:0)
我相信您想要查看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