Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 611

How can I manually turn off edit mode when the last item in a List gets deleted?

$
0
0

I have a simple view in my app that displays a list of checklists. When there are no checklists I display a placeholder view.

The issue I'm having is that when I delete the last item in the list, the EditButton() doesn't switch back to "Edit"; it still says "Done," even thought the list is empty If I then add a new item, the list appears again but in edit mode (a bad UX).

Is there a way to manually "turn off" edit mode after the last item in the list gets deleted?

Image:https://i.stack.imgur.com/lE1yu.png

import SwiftUIstruct HomeView: View {    // MARK: - PROPERTIES    @EnvironmentObject var checklistsVM: Store    @StateObject var homeVM: HomeViewModel = HomeViewModel()    // MARK: - BODY    var body: some View {        NavigationView {            Group {                if(checklistsVM.checklists.isEmpty) {                    EmptyList()                        .environmentObject(homeVM)                                    } else {                    HomeListResults()                        .environmentObject(homeVM)                }            }            .navigationBarTitle("Checklists", displayMode: .large)            .toolbar {                ToolbarItem(placement: .navigationBarTrailing) {                    EditButton()                }            }        }        .navigationViewStyle(StackNavigationViewStyle())    }}

Viewing all articles
Browse latest Browse all 611

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>