Search results for

swiftui

16,633 results found

Post

Replies

Boosts

Views

Activity

Reply to Why is my child SwiftUI view not updating?
Your Button, defined inside ContentView, is only changing the content of the property within the ContentView. You've passed a copy of that to ChildView, so it has a separate value, stored elsewhere in memory. Thus changing ContentView.msg won't alter the value of ChildView.msg.I suspect that if your ChildView's msg property were not an @State value, then it would be recreated. The way SwiftUI works in regard to state is this:Cleans the 'touched' state on all @State variables.Invokes body on a view.Looks at the 'touched' state on the @State variables.If a state property was accessed, it's marked, so that when that state is modified, it triggers another body call.In your ContentView, you're accessing your local @State property, so changes to that property now trigger a redraw. In the ChildView, you're accessing a different @State property. Now, when ContentView.body is invoked a second time, it generates a view containing a new ChildView with a new value (as expected). Then SwiftUI goes to use
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’19
Reply to Getting and setting ScrollView scroll offset in SwiftUI
How did you handle content update in the following function?func updateUIViewController(_ viewController: UIScrollViewViewController, context: Context)The content changes frequently as new items come in (in SwiftUI I have a ForEach that iterates through an array in my BindableObject model). Since the content of my UIScrollView is also SwiftUI, I basically have to remove the subview and add the new one back, which leads to very poor performances.UIScrollViewViewController is a UIViewController that loads the UIScrollView. The content of the UIScrollView is a UIHostingController.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’19
Reply to Anyone figured out how to use equivalent of setRootViewController in SwiftUI?
What exactly is it you're trying to do? If you want to replace what's on screen entirely, then you can ultimately do that from the SceneDelegate, just swapping out the UIHostingController containing the ContentView with one containing your LoginView.Alternatively (and possibly a bit more SwiftUI-ish) you could have a special 'switcher' view that exists only to return either the ContentView or the LoginView, based on some value. That value can be an @State variable, and you can drop a binding to it into the environment, allowing others to modify it from inside button actions and the like. You could use an @EnvironmentObject, but that requires a class, etc., so unless you have something like that floating around already, it seems like a plain @Environment item would work.You'd have to define your own EnvironmentKey and extend EnvironmentValues to provide a key-path though. Here's a very simple example, which hasn't been tested at all:enum RootViewOption: Equatable { case content case login } struct Roo
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’19
How to adjust an image size in a list
Hello folks,I'm very new to SwiftUI and I have trouble resizing images in a List.So far, I created an List like this:var body: some View { List(rooms) { room in Image(room.thumbnailName) <- this image is original size 1920x1080. VStack(alignment: .leading) { Text(room.name) Text((room.capacity) people) .font(.subheadline) .foregroundColor(.secondary) } } }Because the original image size is 1920x1080, the List looks very weird. My question: Does anyone of you know how I can resize the image by a property of the imageview so that the List looks accurate?Many thanks in advance.Kind regardsCX8060
1
0
972
Oct ’19
XCode 11 Cavas Preview does not work
hey guys,i tried to follow the Tutorial https://developer.apple.com/tutorials/swiftui/creating-and-combining-views but the Cavas Live Preview only Shows Automatic preview updating paused. Clicking the Resume Button closes the Canvas View, after reopening the Canvas same stopped Preview as before.I also tried This Tutorial: https://medium.com/flawless-app-stories/swiftui-getting-started-372389fff423 but ended in the Same Behavior.
5
0
3.1k
Oct ’19
Reply to Wrong assistant editor
It is very bizarre.I have created a new project in XCode11.IB panel is on the left, the code panel on the right.And I get, after selecting the second VC in IB:- Automatic (2), letting me select one of the 2- Top level objects (1), with only the second VCCan you select the file from the file browser on the left ?Is it a SwiftUI project (guess no as you have a storyboard).Definetely, should file a but
Oct ’19
Reply to SwiftUI List performane
My guess is your problem is that you are trying to filter the list directly or the array you pass to the list. Which leads to to whole thing being a big performance hog. Maybe try what Apple themselves showed in their WWDC videos: do not pass your array to „List(array){}“, instead create a List without passing anything „List{}“ and then inside the brackets do a for each with your array, where yo decide via classic SwiftUI „if“ when to render certain elements. This gives you multiple benefits and seems the be the recommended way in case you want to modify list content based on certain States. Apple used this method in their tutorials, to filter favorite items in a list if I remember correctly.Update: Ok, I made small test yesterday and this approach also didnt work. Will keep an eye on this in case soem solution comes into my mindUpdate 3: A collegue found a simple solution:Instead of a complicated workaround, just empty the List array and then set the new filters array. It may be necessary to introdu
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’19
Swift UI previewDevice does not show iPad
I followed SwiftUI Tutorials:https://developer.apple.com/tutorials/swiftui/building-lists-and-navigationand there s a methodpreviewdeviceto add device name to prview codeshttps://developer.apple.com/documentation/swiftui/view/3278637-previewdevicehere is my code:struct LandmarkList_Previews: PreviewProvider { static var previews: some View { ForEach([iPhone SE, iPhone XS Max, iPad Pro (9.7-inch), Apple TV], id: .self) { deviceName in LandmarkList() .previewDevice(PreviewDevice(rawValue: deviceName)) .previewDisplayName(deviceName) } } }so when I do the preview, I can see iPhone, but I just see a blank page in iPad
2
0
1.5k
Oct ’19
Reply to SwiftUI view gets wider than host/parent view?
I used one of my tech support tickets and was told it's a bug in SwiftUI. If I can't even do a simple layout like this, I'll go back to UIKit for now. If anyone knows how to fix it, I'd love to know.Text in top HStack is completely offscreen. Pickers are partly off screen. (Running on iPhone SE size screen is worst; other screen sizes also have problems.)struct ContentView: View { @State var choice: Int = 10 @State var choice2: Int = 10 var body: some View { return VStack { HStack { Text(Some text here) Spacer() Text(Foo baz) } HStack { Picker(selection: self.$choice, label: Text(C1)) { ForEach(0..<10) { n in Text((n) a).tag(n) } } Picker(selection: self.$choice2, label: Text(C2)) { ForEach(0..<10) { n in Text((n) b).tag(n) } } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’19
SwiftUI, Core Data and API (JSON)
Hello,I'm looking for a tutorial in SwiftUI with Core Data. I'll build an app with an online and offline options. So the app needs to download data from an API service. Load the data into the Core Data, then the app needs to read the data from core Data. The user needs also an option to synchronize the data back.Does somebody know where I can find a tutorial for this?Kind Regards,Kitty
2
0
4.3k
Oct ’19
Reply to Splitview in SwiftUI
Note that as of the release version of SwiftUI that would be...NavigationView { ... } .navigationViewStyle(StackNavigationViewStyle())In keeping with all of the general structs as styles changes in SwiftUI.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’19
Reply to How can create a share sheet/view with SwiftUI for iOS 13 ?
@Jim Dovey Thank you very much for your detailed, complete, understandable and complete answer!As I now see your code above, implementation in SwiftUI is similar, but as a new user, - unfortunately - I had not fully understood it and had trouble with it as I had not found it anywhere in any documentation or third party example.I didn't know how to create (override) a SwiftUI UIViewControllerRepresentable view for that.Personally I don't mind that the (share) sheet view opens across the screen, because now I think that's the way it is in iOS 13.I am wrong ? In the past, it was different, but I think it now opens up to full screen.After all, share view is not a built-in function common to all apps and ready to use it?I suppose it should be a standard code supported by Apple and apply to all apps. Because this is how I imagine it should be.But thanks to you, my question has been completely resolved and I believe you will help many more people!Really your code works perfectly for me just like I
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’19
UserDefault and EnvironmentObject are crashing preview
I want to have different accounts in an app and save, which one was last used. To do this, I worked with UserDefaults. I also want to share the accounts all over my app in different views. Using EnvironmentObject works just fine for building and running the app, but the preview in canvas does not work.import SwiftUI import Combine final class UserData: ObservableObject { @Published var currentUser: User = userData.first{$0.id == UserDefaults.standard.integer(forKey: currentUser)}! { didSet { UserDefaults.standard.set(self.currentUser.id, forKey: currentUser) } } @Published var user = userData }import SwiftUI struct ShowTrainingView: View { @State var showAccounts = false @EnvironmentObject var userData: UserData var body: some View { NavigationView { Text() .navigationBarTitle(Trainieren) .navigationBarItems(trailing: Button(action: { self.showAccounts.toggle() print(button pressed) }) { Image(systemName: person) .imageScale(.large) }) } } } struct ContentView_Previews: PreviewProvider { sta
2
0
2.3k
Oct ’19