TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Switching to edit mode on a detailed view

Forums > SwiftUI

I have a view that is a detailed view, much like when you view a single contact in the contacts app. I'd like to have an edit button on the contacts app that allows you to edit the details just like the contacts app allows. I'm not sure the best way to do this, do I somehow have a single view that changes in response to the edit button, or should I load an entirely new view somehow? In the contacts app, the edit button doesn't seem to bring up a sheet, but "disolves" from one view to another.

2      

Ok I've played around and here's what I've come up with.

@State private var isEditing

Toolbar button that toggles isEditing

Giant If / Else that switches between my normal view and a textfield editing view.

I got my edit button to switch to done with the following, and the "withAnimation" gives me the fade.

        .toolbar{
            Button(isEditing ? "Done" : "Edit"){
                withAnimation{
                    isEditing.toggle()
                }
            }
        }

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.