I am learning swift and trying to pass a variable to a sheet but it isn’t changing the variable when the sheet pops up, is there a different way to do this?
let bottomSheet = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "bottomSheet")
if let sheet = bottomSheet.sheetPresentationController{
sheet.detents = [.medium()]
sheet.prefersGrabberVisible = true
sheet.preferredCornerRadius = 24
sheet.prefersGrabberVisible = true
}
bottomSheet.isEnabled = true
self.present(bottomSheet, animated: true, completion: nil)
And in the bottomSheet view controller I have the variable
var isEnabled: Bool = false
But even though I put true it always shows as false
2
Answers
Try it like this, what you need to do is specify it as a view controller.
sheetPresentationController only work for ios 15 and later, for previously versions you need to set .custom modalPresentationStype
// MARK: – UIViewControllerTransitioningDelegate
and Add Presentation controller as given