2017-04-13 73 views
0

有一種方法來禁用默認UIMenuItem如何禁用默認的UIMenuItem而不影響消息UIMenuItem?

enter image description here

在不影響消息UIMenuItem? enter image description here

viewDidLoad中:

JSQMessagesCollectionViewCell.registerMenuAction(#selector(UIResponderStandardEditActions.delete(_:))) 
    UIMenuController.shared.menuItems = [UIMenuItem.init(title: "Delete", action: Selector(("delete")))] 
+0

你想禁止複製 - 刪除等? – Jack

+0

@Jack是的,也可以禁用可選 –

+0

在'cellForRow方法中嘗試這個'cell.textView.selectable = false' – Jack

回答

0

使用

cell.textView.selectable = falsecellForRow方法

+1

實際上,你必須首先檢查textView是否不爲零,然後將'isSelectable'設置爲false,否則你會得到按下AccessoryButton時崩潰 –

0

在這裏,你選擇長按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 
    } 
} 

}

相關問題