在這裏,你選擇長按messageBubble時會出現什麼。
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)
}
然後你選擇你想要的物品後會發生什麼,
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
}
}
}
你想禁止複製 - 刪除等? – Jack
@Jack是的,也可以禁用可選 –
在'cellForRow方法中嘗試這個'cell.textView.selectable = false' – Jack