# Strange behavior when changing view

**URL:** <https://forums.kodeco.com/t/strange-behavior-when-changing-view/176758>\
**Category:** macOS by Tutorials\
**Created:** [August 14, 2022, 7:18am UTC](https://forums.kodeco.com/t/strange-behavior-when-changing-view/176758 "2022-08-14T07:18:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattiav8](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/mattiav8/32/102075_2.png) [@mattiav8](https://forums.kodeco.com/u/mattiav8)\
**Post date:** [August 14, 2022, 7:18am UTC](https://forums.kodeco.com/t/strange-behavior-when-changing-view/176758/1 "2022-08-14T07:18:57Z")

</div>

Good morning, could anyone help me solve this behavior when changing view? I have a View used as sidebar with different NavigationLinks, one to create a Record, one to create an Account, one to show all records, and the last one to show specific account’s records.

```auto
NavigationView {
            VStack(alignment: .leading) {
                Group {
                    Text("Records")
                        .font(.system(size: 18))
                        .fontWeight(.bold)
                        .padding(.top, 5)
                    NavigationLink(destination: AddRecord(auxiliaryAccounts: $auxiliaryAccounts, auxiliaryArray: $auxiliaryArray, exercise: $exercise)) {
                        Label("Add Record", systemImage: "plus.app")
                    }
                }
                Group {
                    Text("Accounts")
                        .font(.system(size: 18))
                        .fontWeight(.bold)
                        .padding(.top, 5)
                    NavigationLink(destination: AddAuxAccount(auxiliaryArray: $auxiliaryArray, exercise: $exercise, secondaryAccount: $secondaryAccounts)) {
                        Label("New account", systemImage: "plus.app")
                    }
                }
                Divider()
                Group {
                    Text("Ledger")
                        .font(.system(size: 18))
                        .fontWeight(.bold)
                    NavigationLink(destination: TableView(tableData: exercise.entries, accountName: "General Ledger", accountNumber: 0)) {
                        Label("General Ledger", systemImage: "chart.line.uptrend.xyaxis")
                    }
                }
                Divider()
                Group {
                    Text("Accounts")
                        .font(.system(size: 18))
                        .fontWeight(.bold)
                    List(filteredAccounts, id: \.id!, selection: $selectedAccount) { account in
                        NavigationLink(destination: TableView(tableData: account.entry, accountName: account.name, accountNumber: account.number), label: {
                            VStack(alignment: .leading) {
                                Text("\(account.number)")
                                Text(account.name)
                            }.padding(10)
                        })
                        Divider()
                    }.searchable(text: $searchQuery, prompt: "Search for account")
                        .onChange(of: searchQuery) { _ in
                          filterAccounts()
                        }
                        .onSubmit(of: .search) {
                        filterAccounts()
                      }
                }
            }
            .onAppear {
                loadAccounts()
                filterAccounts()
            }
            .listStyle(SidebarListStyle())
            .frame(minWidth: 250, idealWidth: 250, maxWidth: 300)

            TableView(tableData: exercise.entries, accountName: "General Ledger", accountNumber: 0)
        }

```

The problem resides when I switch view. I can navigate perfectly from “Accounts List” view (any of them) to one of the other three, but if I switch between “Add record” and “Add account”, nothing happens, the current view remain active, but as soon as I select again an “Accounts List” view, the app first open the selected one (correctly) and then it switch to the previous selected (Add Record or Add Account), as if it save the selection somewhere and it execute it only if I select a view from the list. All destination views are made the same way, starting with a VStack, so I think the problem resides in my Sidebar.  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![sarah](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sarah/32/111112_2.png) [@sarah](https://forums.kodeco.com/u/sarah)\
**Post date:** [August 14, 2022, 8:55am UTC](https://forums.kodeco.com/t/strange-behavior-when-changing-view/176758/2 "2022-08-14T08:55:13Z")

</div>

Hi,

`NavigationLink` does not work well in macOS, at least not in the current version.

I recommend having the items in your sidebar set a property or properties and have a detail view that uses these to decide what to show.

Right now, your detail view is preset to show a `TableView` so that will always be the default. If you change this to a view that makes its own decisions about what to show: `TableView`, `AddRecord`, `AddAuxAccount` or whatever, I think you will have much more success.

Sarah

---

<div class="post-metadata">

**Author:** ![nkalvi2](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/nkalvi2/32/102075_2.png) [@nkalvi2](https://forums.kodeco.com/u/nkalvi2)\
**Post date:** [August 14, 2022, 2:09pm UTC](https://forums.kodeco.com/t/strange-behavior-when-changing-view/176758/3 "2022-08-14T14:09:50Z")

</div>

In MacOS 13 beta 5 and Xcode 14 beta 5, following is logged during this strange behaviour:

> SwiftUI encountered an issue when pushing a NavigationLink. Please file a bug.

But it works as expected after adopting to `NavigationSplitView`

```auto
NavigationSplitView {

} detail: {
    TableView(tableData: exercise.entries, accountName: "General Ledger", accountNumber: 0)
}

```

---

<div class="post-metadata">

**Author:** ![sarah](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sarah/32/111112_2.png) [@sarah](https://forums.kodeco.com/u/sarah)\
**Post date:** [August 14, 2022, 10:53pm UTC](https://forums.kodeco.com/t/strange-behavior-when-changing-view/176758/4 "2022-08-14T22:53:54Z")

</div>

Apple has changed navigation completely in the new system. You will need to use `NavigationSplitView` instead of `NavigationView`. In my tests so far, this seems to work really well.
