Post

Replies

Boosts

Views

Activity

NavigationSplitView(sidebar:content:detail:) does not show View in content closure
View using NavigationSplitView(sidebar:content:detail:) in SwiftUI on tvOS does not show the View in the content closure and does not allow proper navigation. This occurs when NavigationSplitViewStyle is .automatic or .prominentDetail. It also occurs when not specified. You can avoid using this sidebar style by adding .navigationSplitViewStyle(.balanced). However, I would like to build an app employing this View. I would be glad to know what you have noticed and if you have any advice. Code Here is the code to reproduce it Just replace it with this and somehow the phenomenon occurs. import SwiftUI struct ContentView: View { @State var selected:Int? @State var selected2:Int? var body: some View { NavigationSplitView { List(selection: $selected){ NavigationLink(value: 1){ Label("1", systemImage: "1.circle") } NavigationLink(value: 2){ Label("2", systemImage: "2.circle") } NavigationLink(value: 3){ Label("3", systemImage: "3.circle") } } .navigationTitle("Sidebar") } content: { if let selected = selected { List(selection: $selected2){ NavigationLink(value: 1){ Label("1", systemImage: "1.square") } NavigationLink(value: 2){ Label("2", systemImage: "2.square") } NavigationLink(value: 3){ Label("3", systemImage: "3.square") } } .navigationTitle("Content \(selected)") } else { Text("No Selected") } } detail: { Group { if let selected2 = selected2 { Text(String(selected2)) }else{ Text("No Selected") } } .navigationTitle("Detail") .frame(maxWidth: .infinity, maxHeight: .infinity) } .navigationSplitViewStyle(.prominentDetail) } } Environment tvOS 18 Simulator (22J356) macOS 15.1 beta (24B5055e) Xcode 16.0 (16A242d) How to Reproduce Open the attached project with Xcode. Build the project on Apple TV with Xcode. press any button on the sidebar Confirm that the View in the content closure is not displayed. Actual Behavior The View in the content closure is not displayed, and the View in the detail closure is displayed. (4/4) Correct Behavior The View in the content closure is displayed, and when the button of the View is pressed, the View in the detail closure is displayed.
0
0
157
Sep ’24
When using a SwiftData value for the customizationID of a TabView, that ID is not unique for a particular behavior.
In the customizationID modifier of the TabView, if I use an ID with a SwiftData value, it returns the following error when I open a new window on iPadOS: “Not unique” even when using a UUID. I can't do anything about it, so I'm posting it here. Any advice that could help me on the way to solving this problem would be appreciated. Thread 1: "Fatal: supplied item identifiers are not unique. Duplicate identifiers: {(\n "Tab.Custom.1C350509-C28A-4C41-85A0-3EA57779DB1B"\n)}" Below is a portion of the code that reproduces this phenomenon. I believe it is sufficient for your needs, but if you need more code, we can accommodate. struct ContentView: View { @Environment(\.modelContext) var modelContext @Query private var tags: [Tag] @AppStorage("Customization") private var customization: TabViewCustomization @State private var isAdding = false @State private var tagName = "" var body: some View { TabView { Tab("Home", systemImage: "house") { NavigationStack { Label("Home", systemImage: "house") .toolbar { ToolbarItem(placement: .primaryAction) { Button { isAdding.toggle() } label: { Label("Add Tag", systemImage: "plus") } } } } } .customizationID("Tab.Home") Tab("Workplace", systemImage: "building.2") { NavigationStack { Label("Workplace", systemImage: "building.2") .toolbar { ToolbarItem(placement: .primaryAction) { Button { isAdding.toggle() } label: { Label("Add Tag", systemImage: "plus") } } } } } .customizationID("Tab.Workplace") Tab("Apple Store", systemImage: "apple.logo") { NavigationStack { Label("Apple Store", systemImage: "apple.logo") .toolbar { ToolbarItem(placement: .primaryAction) { Button { isAdding.toggle() } label: { Label("Add Tag", systemImage: "plus") } } } } } .customizationID("Tab.AppleStore") TabSection { ForEach(tags) { tag in Tab(tag.name, systemImage: "tag") { NavigationStack { Label(tag.name, systemImage: "tag") .toolbar { ToolbarItem(placement: .primaryAction) { Button { isAdding.toggle() } label: { Label("Add Tag", systemImage: "plus") } } } } } .customizationID("Tab.Custom.\(tag.id.uuidString)") } } header: { Label("Custom", systemImage: "tag") } .customizationID("TabSection.AppleStore") .sectionActions { Button { isAdding.toggle() } label: { Label("Add Tag", systemImage: "plus") } } } .tabViewCustomization($customization) .tabViewStyle(.sidebarAdaptable) .alert("Create Tag", isPresented: $isAdding) { TextField("Tag Name", text: $tagName) Button("Cancel") { tagName = "" isAdding = false } Button("Done") { let tagList = tagName.components(separatedBy: .whitespaces) for tagItem in tagList { if tagItem != "" && tags.filter({return $0.name == tagItem}).isEmpty { let newTag = Tag(name: tagItem) modelContext.insert(newTag) } } try? modelContext.save() tagName = "" isAdding = false } } } } import SwiftData import Foundation @Model final class Tag: Identifiable { var id: UUID = UUID() var name: String = "" init(name: String) { self.id = UUID() self.name = name } } How to reproduce Implement the above code so that it works. Build the application on the actual iPad device using Xcode. Add tags (data) Open a new window and check the UI behavior. Correct Behavior The ID is not actually unique. Or, if it is unique, it should not freeze without generating an error. Actual Behavior The ID should be set to be unique, but it freezes with an error that it is not unique. Environment iPadOS 18 RC (22A3354) Xcode 16.0 (16A242)
0
0
246
Sep ’24