我有一個UICollectionView,每個單元格都有一個UITextView。我試圖在長按TextView中的文本並從上下文菜單中選擇「刪除」時刪除整個單元格。獲取哪個UIcollectionviewcell觸摸的文本視圖是
我知道我可以覆蓋重寫
func delete(_ sender: Any?) {//I want to delete cell from here}
和
刪除override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(delete(_:))
{
return true
}
return super.canPerformAction(action, withSender: sender)
}
我只是不知道如何找到當前單元格我英寸
您可以通過使用indexPath.row爲UITextView的分配標籤,並通過這個這個標籤獲得的細胞。 – nynohu
但是,如何知道上下文菜單中的哪個文本視圖? –
在'cellForItemAtIndexPath'中,設置'cell.textView.tag = indexPath.row'。在func中刪除(_ sender:Any?){讓textView:UITextView = sender as! UITextView的; indexPath.row = textView.tag。只要調用delete collectionCell方法}' – nynohu