Post

Replies

Boosts

Views

Activity

Reply to NavigationSplitView and Lists in Child views
And additionally, in the case without selPriv, I end up getting this warning on device when the selection doesn't work: 2023-09-14 10:44:45.305377-0700 NavSplitView[20843:16029318] [Assert] Collection view focus state got out of sync. Expected <SwiftUI.ListCollectionViewCell: 0x13d050a00; baseClass = UICollectionViewListCell; frame = (116 44; 288 44); layer = <CALayer: 0x600002305540>> to be the current managed subview but found <SwiftUI.ListCollectionViewCell: 0x14d01a000; baseClass = UICollectionViewListCell; frame = (116 44; 288 44); alpha = 0; layer = <CALayer: 0x6000023fa520>>. It doesn't happen when I use the private selection case (but the selection still doesn't highlight).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’23
Reply to NavigationSplitView and Lists in Child views
As an experiment I tried a private state variable for the selection. Selections are highlighted (but the detail is broken), but as soon as I hook up the onChange, the detail works but the selections fail struct ContentStringX: View { let content = [StringItem(item: "Here"), StringItem(item: "There"), StringItem(item: "Everywhere") ] @Binding var selection : StringItem? @State private var selPriv : StringItem? var body: some View { List(content, selection: $selPriv) { c in NavigationLink(value: c) { Text(c.item) } } .onChange(of: selPriv) { new in selection = selPriv } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’23
Reply to CoreData / SwiftUI List selection question
OK, so I have figured out what was going on in SampleTrip. It turns out that TripListItem includes a NavigationLink so copying that pattern var body: some View { NavigationSplitView { List(players, selection: $selectedPlayer) { player in NavigationLink(value: player) { Text(player.shortName ?? "") } } .navigationTitle("Players") } detail: { if let p = selectedPlayer { Text("detail \(p.shortName ?? "")") } else { Text("detail empty") } } Now works. So in this case, I don't need to pass in id. Any thoughts on whether using the NavigationLink here is the preferred approach? At least part of the mystery is resolved!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’23
Reply to CoreData / SwiftUI List selection question
The code: @FetchRequest(sortDescriptors: []) private var players: FetchedResults<PlayerEntity> @State private var selectedPlayer : PlayerEntity? var body: some View { NavigationSplitView { List(players, selection: $selectedPlayer) { player in Text(player.shortName ?? "") } .navigationTitle("Players") } detail: { if let player = selectedPlayer { Text("Do Something") } } } The list appears, but is not selectable, and the detail view doesn't get presented. I also tried using the same List/ForEach style of the sample code.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’23