|
Currently in one of my views I have setup a conformation dialog that triggers appropriate booleans to show corresponding sheets. Each sheet shown is a view, more precisely a UIViewControllerRepresentable. All works perfectly!
I find this multiple sheet appraoch very messy and besides I am going to need the same setup at least once elsewhere. So I want to refactor this and pull the dialog out in a way that i have an object that can show the dialog (options) and consequently show the corresponding sheet. I say sheet, because I think I can't just present a view, right? (iOS 16 can?). Tried several approaches, but non succesful so far. The closest to my original setup in the original view is this:
This builds, but the sheets do not get presented... Ant nudges in the right direction would be helpfull. Other approaches too! |
|
Rather than a collection of booleans, consider creating an enum for the different types of sheet that may be needed.
Then your buttons can set this state variable, e.g.
This allows you to have a single sheet based on your enum. It will display when
|
|
@https://www.hackingwithswift.com/users/scottmatthewman I tried that approach, but it somehow didn't work for me. Gonna have another go at it and report back here. Thanks! |
|
@scottmatthewman shouldn't it be
I'm still on 13.4.1, so maybe |
|
@scottmatthewman I see what you mean, those changes in the calling view. I've implemeted that, and its a little bit cleaner with just one sheet, but I'd like to be able to have one class/struct that can be called from anywhere, that presents a confirmation dialog (ie list of buttons) and handles serving the right views (sheet or otherwise) and handles the result (return the selectedImage). Fort completion sake, my current implementation based upon your tips:
|
|
SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.