Post

Replies

Boosts

Views

Activity

TipKit popover inside ForEach Loop
I've encountered a problem when placing a tip on an element in a ForEach loop. As long as there is only one element in the list the tip will be shown. But if there are more than one element the tip does not appear on iOS and iPadOS. How do I get the tip to be displayed when several elements are displayed? Is it allowed to use the popoverTip() modifier in a ForEach loop or should it be avoided? Interestingly, it works if you run the attached sample code on macOS. Then the tip is displayed on the “Third” element. import SwiftUI import TipKit struct ContentView: View { private var elements: [String] = ["First", "Second", "Third"] let tip = DemoTip() var body: some View { NavigationStack { List { Section { ForEach(elements, id: \.self) { element in Text(element) .popoverTip(tip) } } } } } } struct DemoTip: Tip { var title: Text { Text("Demo Tip") } } @main struct TipKitTestApp: App { init() { #if DEBUG Tips.showAllTipsForTesting() #endif try? Tips.configure([.displayFrequency(.immediate)]) } var body: some Scene { WindowGroup { ContentView() } } }
3
0
305
Jul ’25
Reset NavigationStack when changing selection of NavigationSplitView
I'm trying to build an app that has a NavigationSplitView and a NavigationStack in the detail View. The normal flow works fine, but if I navigate to the second page on the detail view and then select another menu item (i.e. the second item), I'm still on the detail page of the first menu item. The underlying view of the second detail view changes. This can be observed by the change of the back button label. How do I ensure that my NavigationStack is also reset when I change the selection? import SwiftUI enum Option: String, Equatable, Identifiable {     case first     case second     var id: Option { self } } struct ContentView: View {     @State private var selection: Option?     var body: some View {         NavigationSplitView {             List(selection: $selection) {                 NavigationLink(value: Option.first) {                     Text("First")                 }                 NavigationLink(value: Option.second) {                     Text("Second")                 }             }         } detail: {             switch selection {             case .none:                 Text("Please select one option")             case .some(let wrapped):                 NavigationStack {                     DetailView(title: wrapped.rawValue)                 }             }         }         .navigationSplitViewStyle(.balanced)     } } struct DetailView: View {     private var title: String     init(title: String) {         self.title = title     }     var body: some View {         List {             NavigationLink {                 Text(title)             } label: {                 Text("Show \(title) detail")             }         }         .navigationTitle(title)     } }
2
1
3.4k
Jan ’23
TipKit popover inside ForEach Loop
I've encountered a problem when placing a tip on an element in a ForEach loop. As long as there is only one element in the list the tip will be shown. But if there are more than one element the tip does not appear on iOS and iPadOS. How do I get the tip to be displayed when several elements are displayed? Is it allowed to use the popoverTip() modifier in a ForEach loop or should it be avoided? Interestingly, it works if you run the attached sample code on macOS. Then the tip is displayed on the “Third” element. import SwiftUI import TipKit struct ContentView: View { private var elements: [String] = ["First", "Second", "Third"] let tip = DemoTip() var body: some View { NavigationStack { List { Section { ForEach(elements, id: \.self) { element in Text(element) .popoverTip(tip) } } } } } } struct DemoTip: Tip { var title: Text { Text("Demo Tip") } } @main struct TipKitTestApp: App { init() { #if DEBUG Tips.showAllTipsForTesting() #endif try? Tips.configure([.displayFrequency(.immediate)]) } var body: some Scene { WindowGroup { ContentView() } } }
Replies
3
Boosts
0
Views
305
Activity
Jul ’25
Reset NavigationStack when changing selection of NavigationSplitView
I'm trying to build an app that has a NavigationSplitView and a NavigationStack in the detail View. The normal flow works fine, but if I navigate to the second page on the detail view and then select another menu item (i.e. the second item), I'm still on the detail page of the first menu item. The underlying view of the second detail view changes. This can be observed by the change of the back button label. How do I ensure that my NavigationStack is also reset when I change the selection? import SwiftUI enum Option: String, Equatable, Identifiable {     case first     case second     var id: Option { self } } struct ContentView: View {     @State private var selection: Option?     var body: some View {         NavigationSplitView {             List(selection: $selection) {                 NavigationLink(value: Option.first) {                     Text("First")                 }                 NavigationLink(value: Option.second) {                     Text("Second")                 }             }         } detail: {             switch selection {             case .none:                 Text("Please select one option")             case .some(let wrapped):                 NavigationStack {                     DetailView(title: wrapped.rawValue)                 }             }         }         .navigationSplitViewStyle(.balanced)     } } struct DetailView: View {     private var title: String     init(title: String) {         self.title = title     }     var body: some View {         List {             NavigationLink {                 Text(title)             } label: {                 Text("Show \(title) detail")             }         }         .navigationTitle(title)     } }
Replies
2
Boosts
1
Views
3.4k
Activity
Jan ’23