Questions tagged [swiftui-state]
47 questions
0
votes
2 answers
setTitleColor not working for custom UIButton in .disabled state
I have a form to collect basic user info. There is a "Continue" button on the form that has different appearances based on whether it is in the .enabled or .disabled state.
The .enabled state formatting works fine with the setTitleColor method. But…

Farquad
- 3
- 4
0
votes
1 answer
SwiftUI: Using a Published attribute to displaying a sheet
Good evening!
I’m working on a simple project, where I have a view model, which has published boolean value. I would like to show a sheet when this value is set. However, the sheet function uses the Binding type, meanwhile I have the Published…

Kirill Rud
- 217
- 3
- 9
0
votes
0 answers
updating @State variable in swiftUI not cause to reload when using delegate which called from outside
I have this code:
import SwiftUI
@main
struct MyWatchApp: App {
@State var myEnum: MyEnum = .first
var body: some Scene {
WindowGroup {
getCorrectView()
}
}
func getCorrectView() -> some View {
…

Mahdi Moqadasi
- 2,029
- 4
- 26
- 52
0
votes
1 answer
SwiftUI: Instance member 'enableFilter' cannot be used on type 'ContentView'; did you mean to use a value of this type instead?
I'm a beginner with SwiftUI and I wanted to create a dynamic list with the birthdays of people. I also wanted to integrate a filter that facilitates to find birthdays. But in the lines:
if enableFilter == true {
return json.filter…

Yan
- 3
- 2
0
votes
1 answer
@State var not changing - SwiftUI picker
I am a real newbie in swift, but I am stuck at this problem...
I am building a picker to change an optical prescription, but I am not able to change SPH and CYL values (doubles), while AX works good. Any help?
Also the way that text comes out, I…

Alessandro Bardelle
- 13
- 3
0
votes
0 answers
Cannot switch views through @State binding variable in SwiftUI
I'm trying to pass a state variable between view files in order to navigate between views, but it doesn't seem to work. The "view" variable is updated when the register button is pressed, but it doesn't change the view. This is a simplified version…

Dayem Saeed
- 325
- 5
- 15
0
votes
1 answer
Whats the best way to get SwiftUI Picker() selection to update on app state change?
I'm trying to make a UI with SwiftUI that lists a collection of things that can be of different kinds and can each be updated. I'd like to make the type settable in the UI with a Picker, and I also want the view to update when the item is modified…

ParcelCloak
- 58
- 6
0
votes
2 answers
Swift UI @State does get set on the first tap
I have a simple list of for a Custom View. What needs to happen is when one of the items are selected it needs to show the detail view for that item. In my code, when I select an item for the very first time, the @Statet selectedListener does not…

Minon Weerasinghe
- 312
- 1
- 3
- 13
0
votes
1 answer
SwiftUI State var array not updating child views
For some reason I don't understand, when I add/remove items from a @State var in MainView, the OutterViews are not being updated properly.
What I am trying to achieve is that the user can only "flag" (select) one item at a time. For instance, when I…

Aнгел
- 1,361
- 3
- 17
- 32
0
votes
1 answer
SwiftUI: @State property not updated without weird workaround
I'm experiencing strange behavior with an @State property that isn't being properly updated in its originating view after being changed in another view. I'm using Xcode 12.3 and iOS 14.
What happens is that an @State "session" value-based item and…

Cosmo
- 171
- 1
- 8
0
votes
1 answer
How to switch between views using @State and fullScreenCover in SwiftUI
I'm trying to figure out how to switch between views using @State and fullScreenCover in SwiftUI
I have a main view and 2 simple views (View1 and View2). View1 must open on the tap of the "Show view 1" button, and View2 when typing on the "Show view…

Adelmaer
- 2,209
- 3
- 22
- 45
0
votes
2 answers
@State var doesn't store value
My goal is to pass values between views, from Chooser to ThemeEditor. When the user presses an icon, I'm saving the object that I want to pass and later, using sheet and passing the newly created view with the content of the @State var.
The…

Shaihi
- 3,952
- 4
- 27
- 47
0
votes
1 answer
SwiftUI: how to pass an array to a View to be used in ForEach
I would like to pass an array of elements to a View and show the elements with a ForEach. When I pass an array of a different size than the previous one, it crashes with error Thread 1: Fatal error: Index out of range on line Text(elements[$0]).
My…

Massimo Omodei
- 13
- 1
- 3
0
votes
0 answers
Best practices for SwiftUI state variable encapsulation/ Too many state variables in a complicated view
I'm use to have a class for several complex subviews in a view. Each can encapsulate it's own state. SwiftUI will let you refactor a long view function into subviews but I have not found anything other than passing @Binding variables through the…

madmik3
- 6,975
- 3
- 38
- 60
0
votes
1 answer
How can I make a view wrapped in a `State` property update with SwiftUI
The code below creates a simple HStack that ends up looking like this:
The problem is that hitting "increment" increments "Count" but not "Nested". Does anyone know why this is the case and possibly how to fix this? Or do SwiftUI views just…

GeorgeLyons
- 51
- 6