Post

Replies

Boosts

Views

Activity

How would I use NavigationSplitView where I previously used a binding with NavigationLink?
I’ve been trying really hard to get to try NavigationSplitView in my app, but I’m really confused as to how to use it when I’m not passing values in my app. I just have bindings. I really want to use the new features that come with the new API, but I just can’t figure out how. Attached is what I’m doing now, any help figuring out how to do this exact thing with the new NavigationSplitView API would be greatly appreciated. // ContentView     var body: some View {         NavigationView {             Sidebar() .navigationTitle("Formats")             Detail()         }     } // Sidebar @State private var isShowingDetail = true    var body: some View {         List {             NavigationLink(destination: Detail().navigationTitle(“Detail"), isActive: $isShowingMLAView) { Label(“Detail", systemImage: “ellipsis.circle")} // Other Navigation Links here...
0
1
753
Nov ’22
Starting up my multiplatform SwiftUI app on Mac results in an empty window when opening a new window works
This is a bit of a weird one, but I’m having an issue where when I run my SwiftUI app on Mac to test (pressing command + r pr pressing the play button, previews work fine), it opens a blank window without any content in it. If I open a new window by pressing command + n, the actual window of the app shows up. What’s weirder is that this only happens on one Mac; I’ve tried it on another one with the same Xcode project, same code, same OS version, same Xcode version, etc, and the issue doesn’t occur; the app opens the normal window as expected. It also doesn’t happen on iOS and iPadOS, both on devices or in the simulator. I’m thinking it might be some cache files that messed something up and are preventing the right window from loading, but unlike the iOS simulator, I can’t delete the app and rerun to “reinstall.” Does anyone know how to do this? Any help would be greatly appreciated. Super annoying and certainly not shippable; I don’t want to use up one of my TSIs to figure it out since nobody else on the entire internet has had this issue. Maybe it’s just a SwiftUI bug? I don’t know! I’ve attached some code below and a screen shot of the issue. Thanks! // Main app file @main struct CitationsApp: App {     var body: some Scene {         WindowGroup {             ContentView()         }     } } // ContentView struct ContentView: View {     @State private var isShowingMLAView = true     var body: some View {         NavigationView {                     List {                         NavigationLink(destination: MLA().navigationTitle("Create Citation"), isActive: $isShowingMLAView) {                             Label("MLA", systemImage: "doc.text")}                                                                       }                     .listStyle(.sidebar)                     .navigationTitle("Citations")                 }     } }
0
1
581
Oct ’22
Couple questions about NavigationSplitView in SwiftUI
I'm in the process of building a SwiftUI app with a Sidebar and Detail View. I've run into some issues and I need some help fixing them: When the app is launched, my detail view shows up at the right of the sidebar. Great! However, the button that is supposed to navigate to that view isn't highlighted, which could cause user confusion. How do I make this button "light up" (with that blue background indicating to the user that it is selected, highlighted) and make the code so that this view opens up when the app opens (like in other Apple apps, see Music and Files) When I click on one of my sidebar items (which are just NavigationLinks), the background doesn't turn blue (highlight) to indicate that item is selected. I feel like this would cause user confusion, and I'd like to figure out why my code doesn't do this. One side note and a useful piece of information: whenever I click the NavigationLink in the sidebar, the console prints this: onChange(of: UpdateTrigger) action tried to update multiple times per frame. In the macOS app, upon launch, the detail view shows up. Great. What doesn't show up is my sidebar with the options on it. How do I make it so that the sidebar shows up no matter what unless the user specifies to remove it from view? Attached are some images and my code. Thanks, y'all! struct ContentView: View {     var body: some View {                  // NavigationSplitView for the sidebar                  NavigationSplitView {                          // List of the options                          List {                                  // NavigationLink for my button                                  NavigationLink {                                          // Linking to my main view that I want to show up upon launch of the app                                          MainView()                                          // Label to make it look pretty                                      } label: {                     Label("Main View", systemImage: "icloud")                 }                                  // Make the sidebar actually look like a sidebar                                  .listStyle(.sidebar)                              }                          // NavigationTitle at the top of the sidebar                          .navigationTitle("Cling")                          //                      } detail: {                          // Make it so that the main screen shows up upon launch (however, this doesn't make the button light up to signify that the user has selected that view)                          MainView()         }     } }
2
1
2.4k
Jun ’22
Simple Issue: How do I extend my form to my entire modal?
This is a weird but simple issue that I'm having and I'm hoping someone can figure it out: I have a modal that contains a form and a NavigationView for the navigationTitle and navigationBarItems. However, the form doesn't take up the whole modal, leaving this weird white gap between the navigationBar and form. Is there any way to remove this weird gap? Attached is my code. Thanks!  var body: some View {         // Create Navigation View for the title at the top         NavigationView {             VStack(spacing: 0) {                                  Text("")                 // Navigation Title                                      .navigationTitle("Modal Title").navigationBarTitleDisplayMode(.inline)                 // Creating Cancel Button                     .navigationBarItems(leading: Button(action: {                         self.isPresented = false                     }, label: {                         Text("Cancel").frame(maxWidth: .infinity, alignment: .leading)                         .frame(alignment: .top)}))                 // Creating Add button                     .navigationBarItems(trailing: Button(action: {                         self.isPresented = false                         print("\(self.taskName)")                         print("\(self.description)")                     }, label: {                         Text("Add").frame(maxWidth: .infinity, alignment: .leading)                         .frame(alignment: .top)}))                 // Creating form for the text fields                 Form {                                          // Section 1: Title and Desctiption text views                     Section {                         TextField("Title", text: $taskName)                         TextField("Description", text: $description)                             .ignoresSafeArea()                                                                               }                                          Section {                                                  DatePicker("Date", selection: $date, in: Date()..., displayedComponents: .date)                             .datePickerStyle(GraphicalDatePickerStyle())                                                                                                   }                                                                   }                     }                                      }                              }
0
0
497
Jun ’22
Text Alignment in SwiftUI
I've created an HStack and am trying to make one of those titles that you find in Apple apps (Messages, Mail, etc.) at the top left. I've gotten the text to the right size, made it bold, and aligned to the left and used .frame(alignment: .top) to align it to the top, but for some reason it stays in the middle. What am I doing wrong? Below is the code and an image of the issue. import SwiftUI struct HomeScreen: View {     var body: some View {         HStack{             Text("Tasks").font(.largeTitle).fontWeight(.bold).frame(maxWidth: .infinity, alignment: .leading).padding()                 .frame(alignment: .top)                  }          } struct HomeScreen_Previews: PreviewProvider {     static var previews: some View {         HomeScreen()     } } } ![]("https://developer.apple.com/forums/content/attachment/9d21e948-cd73-404c-9b3c-02f7898c8cfe" "title=Screen Shot 2022-06-05 at 3.49.25 AM.png;width=704;height=1350")
4
0
7.8k
Jun ’22