Questions tagged [onappear]

42 questions
0
votes
1 answer

OnAppear does not update State, button action does

In a ContentView(), I have a the below: @State var entries = [AType]() var body: some View { NavigationView { List { if self.entries.count == 0 { Button { …
GarethPrice
  • 1,072
  • 2
  • 14
  • 25
0
votes
0 answers

run code automatically after view appeared

Is there a way of running code after the view appeared? If I use ".onAppear", my code gets executed and when it is finished, the view appears. But I want that the view appears first and then my code gets executed automatically. Thanks
Pjaks
  • 251
  • 1
  • 11
0
votes
0 answers

How to keep timer going when inside navigation link SwiftUI?

so I'll keep it simple: I have a timer that runs on appear of this view as follows: struct FocusView: View { @State var isTimerRunning = false @State private var startTime = Date() @State private var timerString = "0.00" @State private var timer =…
alex
  • 118
  • 1
  • 6
0
votes
0 answers

Infinite loop onAppear in SwiftUI, but init() gives me another error

I want to call "getTestCounts" before displaying "Text(testCounts.counts[index].number)". However, if I use onAppear, I end up with an infinite loop. I think that since we are creating unique IDs with UUID and spinning them around in ForEach, we end…
Kintsuba
  • 1
  • 1
0
votes
1 answer

SwiftUI Dynamically Create Enum or

I have a custom picker where the contents of the picker are created from a downloaded JSON file. In an effort to provide better accessibility for challenged users, I am trying to use the .accessibilityFocused modifier to focus VO on a user's…
kittonian
  • 1,020
  • 10
  • 22
0
votes
0 answers

SwiftUI: Why is onAppear executing twice?

StepPreview is printed twice. Once when the view loads (when tab is selected) and again when the user returns to the tab. Is this expected when using onAppear on a NavigationView? struct StepPreview: View { var body: some View { …
Mxyb
  • 83
  • 1
  • 9
0
votes
0 answers

onAppear modifier called twice when applying .navigationViewStyle(.stack) on NavigationView

[Summarize the problem] .onAppear modifier called twice when using .navigationViewStyle(.stack) on NavigationView. [Describe expected and actual results] I am expecting .onAppear to be called once but .onAppear is called twice. EDIT: I Removed the…
0
votes
1 answer

How to detect that LazyVGrid's items get re-built?

In my app, LazyVGrid re-builds its contents multiple times. The number of items in the grid may vary or remain the same. Each time a particular item must be scrolled into view programmatically. When the LazyVGrid first appears, an item can be…
0
votes
0 answers

SwiftUI load all views in TabView on appearance of the first tab

My TabView looks like this: var body: some View { TabView { TabView1() .tabItem() { Image("...") Text("...") } .onAppear { ??? } TabView2() …
0
votes
1 answer

SwiftUI onAppear not working properly when trying to read UIKit's UIDevice orientation

Using iOS14.4.2, Swfit5.3.2, XCode12.4, physical device = iPhoneXS On appearing, I am trying to write the current device orientation into a Static property and later use it inside a View. However, the value is not correctly written when…
iKK
  • 6,394
  • 10
  • 58
  • 131
-1
votes
1 answer

Is there a substitute for onAppear?

I am a novice at SwiftUI and I am playing around with Text-To-Speech functions. I have gotten it to work, but I now want the app to automatically speak a string when opened. I have set it up like so: import SwiftUI import AVFoundation struct…
KodeKat
  • 15
  • 4
-1
votes
1 answer

xcode swiftui button how to press it programmatically (assign an ID to it ?)

I have a working barcode scanner app (i followed this tutorial https://www.youtube.com/watch?v=44APgBnapag), the only thing Is missing for me if to start the barcode scanner at load instead of the user pressing the button var body: some View { …
Jintor
  • 607
  • 8
  • 32
1 2
3