To show a view controller, you need to instatiate it and use the instance.
I cannot find any code to instantiate a view controller, how are you doing it?
And you usually do not modify `isHidden` property of a view controller's view when showing a modal view.
Better learn a usual way and you can utilize many techniques found on the web.
When you need to pass some value to another view controller, you usually prepare a property to receive it:
class ModalCalViewController: UIViewController {
//Create a property to receive the value you want to pass
var passedValue: Bool = false
@IBAction func hideChildControllerBtn(_ sender: Any) {
// Button to set view back to hidden
dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
}
//And use the passed value in `viewWillAppear(_:)`
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
//Use passedValue here...
//For example:
if passedValue {
view.backgroundColor = .blue
}
}
}
And instatiate and show the view controller like this:
@objc func handleLongPress(gesture: UILongPressGestureRecognizer) {
guard gesture.state == .began else {return}
let position = gesture.location(in: collectionView)
if let indexPath = collectionView.indexPathForItem(at: position) {
guard let modalCalVC = self.storyboard?.instantiateViewController(identifier: "ModalCalViewController") as? ModalCalViewController else {
print("ModalCalViewController cannot be instantiated")
return
}
let value = true //Get the value you want to pass from `indexPath`
modalCalVC.passedValue = value
present(modalCalVC, animated: true, completion: nil)
} else {
print("Long press not on a cell")
}
}
I assume you have set up the UILongPressGestureRecognizer successfully, and have a property named `collectionView`.
And you need to give a Storyboard ID "ModalCalViewController" on the view controller in your storyboard.