Previous episode: 14. Confirmation Dialogs
Next episode: 16. Model Objects
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
So you can delete images now, and you've got a button to go through with it on your confirmation dialogue. How about another button to launch the dialogue when you actually need it? Your challenge is to add a delete button next to the update image button you already have. And that's what should make the dialogue show up, not just navigating to the detail view. For an extra challenge, see if you can make the delete button only show up when there's actually an image to delete. That should pretty much take care of everything you'll need to do to work with your book's images. So have at it and come back to compare solutions with me. (upbeat music) Hi, again. As always, I hope that went well for you. Here's how I started. Instead of relying on this constant binding, I created another state variable, which looked very much like the showingImagePicker one we already had. And then I use that for the dialogue modifiers' isPresented binding. Before adding a new button, I embedded the existing one in an Hstack. And move the padding to apply to the whole stack, not just the update image button. Then I copied that button code and pasted it above the original. I changed the text on that copy to delete image and I thought that getting rid of the ellipsis seemed better for some reason too, so I did that and switch the variable I was setting to true to be showing dialogue. The buttons here felt tight enough to be dangerous to me, so I put a spacer in between, but that didn't look very good either, so I added another spacer on the left and on the right. Then to complete the extra challenge, making the delete button only show up when there's actually an image to delete, I thought about what I had just changed. I only needed this delete button and top spacer if the image was not nil. Now only that update button would render if there was no image. With that all set up, I went to content view so I could send some books and a library image binding over to the detailed view. I live reviewed. And after setting a book's image, my delete button showed up. Canceling didn't do anything, but dismiss the dialogue and the same for just tapping outside of the dialogue, which is exactly what we want. But hitting delete got rid of both the image and the delete button.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.