Relative Content

Tag Archive for swiftui

How to place a list cells id: into a set to use on another screen?

I am recently retired and learning Swift/SwiftUI to write a tracking program for my forty plus characters in the Star Trek Online game that I have played for years. I will have to enter the data manually as, to my knowledge STO has no API to retrieve a players accounts, character data.
I have many screens written and my SwiftData database set up. I am currently working on a screen to select the traits a character has available to them, (has available/unlocked). This data I am loading from a json file is the Master list and will not change for each trait type, (7 total). My screen has a VStack inside a ZStack which holds an HStack with a vstack and a list inside. the VStack to the left holds a button to select which Master trait list to display for selection. and boxes under it to hold the trait Images that have been selected for the characters build. (see included screen shot) The List on the right shows the selected trait type.
I am using a custom ListCell to display the info. I have a trait is active selection box that I wish to show that the trait is active and place that traits image into a Set that I can store in my data base and retrieve when I select the character it belongs to.
The problem I am trying to solve is how to send the selected trait id: String into the set and display it on the VStack side. I have tried several ways but not working. the last way I tried was to make a class that holds the sets I need and place it in the environment, but I must not fully understand how all that works properly, as it seems to make a set for each cell in my list when I only want to place the selected cell into the set. I have included sample data and the code I am working on. Note I am not trying to use the lists edit toggle feature to select my traits, but my own checkbox. Any help to point me in the right direction would be much appreciated. Thanks!

How to navigate through a questionnaire?

currently I’m struggeling in tinding a solution. I have a main view which loops over CoreData records for questionnaires and displays them in a list within a NavigationStack. Then I have a view that displays a single question of a questionnaire. How would I now handle the navigation through my questions in a choosen questionnaire because my subview is only accepting a single question and I need somewhere to keep track on the status of the current questionnaire.

SwiftUI 3rd level of .sheet() disappears immediately

In MacCatalyst on MacOS Sonoma 14.6 when my app has 3 levels of active sheets the 3rd sheet disappears immediately after presenting, if the 1st level sheet is a modifier on a view in the NavigationStack, rather than a modifier of the NavigationStack. I don’t have this problem in MacCatalyst on MacOS 13.6, on iOS 16.4 or on iOS 17.6. In my real app each one of these NavigationStacks has many sheets, hence the use of the overlays. What’s the right way to make this work on iOS > 16 and macCatalyst on MacOs > 14.6? Thank you

SwiftUI Toggle stops responding after returning from background

Having a weird bug. I am running a beta of ios18.1 btw.. so maybe that’s the issue. I have a few toggle controls on a .medium height share sheet. They work well. If I background the app, and then foreground, one of the toggles stops responding (the bottoms most one in the vstack). Well.. if I tap several times sometimes it works, but certainly not well. Has anyone encountered this?