I want to copy a custom collectionview cell from a viewcontroller to another, the problem is the collectionview cell disappears once I tap on it because of - apparently - adding it in the 2nd viewcontroller's as a subview.
I tried most of the methods here Create a copy of a UIView in Swift
One about Archiving returns nil.
Other about prototypes and structs, it doesn't return a new address for the view.
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
struct ObjectToCopied {
var objToBeRetrieved: UIView? = nil
init(objToSaved : UIView?) {
objToBeRetrieved = objToSaved
}
}
let pickedView : UIView? = collectionView.cellForItem(at: indexPath)
let tempObj = ObjectToCopied(objToSaved: pickedView)
let copiedObj = tempObj
let copiedView = copiedObj.objToBeRetrieved as? UIView
// here the copiedview's address is THE SAME as tempObj's ObjToBeRetrieved.
}
Custom CollectionView cell image example: