SwiftUI Sidebar doesn't remember state

前端 未结 1 733
孤独总比滥情好
孤独总比滥情好 2021-02-05 16:52

I Have this app that uses the new sidebar introduced in iOS14 for iPad os but I can\'t figure out why it doesn\'t remember the state when its hidden

相关标签:
1条回答
  • 2021-02-05 17:10

    List(selection: $selection) for selection binding is macOS only. See this comment in the header:

    /// On iOS and tvOS, you must explicitly put the list into edit mode for
    /// the selection to apply.
    

    As a workaround you could make the previously selected row appear bold, e.g.

     NavigationLink(
            destination: HomeView(),
            tag: Screen.home,
            selection: $selection,
            label: {
                Label("Home", systemImage: "house" )
            })
            .font(Font.headline.weight(selection == Screen.home ? .bold : .regular))
    

    For more see this answer.

    0 讨论(0)
提交回复
热议问题