Post

Replies

Boosts

Views

Activity

SwiftUI Menu with NavigationLinks inside overall NavigationStack
I've read all previous posts on this topic but none seem to address what I'm seeing for iOS 16 and using NavigationStack. I'm also using an overall @EnvironmentObject for navigation state. I have a split view app. In the detail section, I have a NavigationStack surrounding the detail view. Within the detail view (MyView), there is a base view with a "+" button in the toolbar to create a new entity. That opens NewEntityView where I show a grid of buttons for the user to select a type to create a new entity before moving to NewEntityView to fill in the details for the entity. The top row of the grid of buttons takes the user straight to the NewEntityView with a NavigationLink. These work fine. The next row of buttons present a menu of sub-types and then should take the user to the NewEntityView view. These buttons do not work. Code (simplified to not have clutter): SplitViewDetailView: struct SplitViewDetailView: View { @EnvironmentObject var navigationManager: NavigationStateManager @Binding var selectedCategory: Route? var body: some View { NavigationStack(path: $navigationManager.routes) { // other irrelevant stuff MyView() } .environmentObject(navigationManager) .navigationDestination(for: Route.self) { $0 } } } MyView: struct MyView: View { @EnvironmentObject var navigationManager: NavigationStateManager var body: some View { List { // other stuff } .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button(action: {}, label: { NavigationLink(value: Route.newTypeSelect) { Image(systemName: "plus") .frame(width: 44, height: 44) } } ) } } .navigationDestination(for: Route.self) { $0 } } SelectTypeView: struct SelectTypeView: View { var body: some View { ZStack { VStack { // Top row with no subtypes HStack { ForEach (topRows, id: \.self) { type in NavigationLink(value: Route.newEntityDetails(type.rawValue)) { <-- these work Text(type) } } } HStack { ForEach (middleRow, id: \.self) { type in Menu { ForEach (subtype[type], id: \.self) { sub in NavigationLink(value: Route.newEntityDetails(sub.rawValue)) { <-- these go nowhere Text(sub) } } } label: { Text(type) } } } } } } } NavigationStateManager: class NavigationStateManager: ObservableObject { @Published var routes = [Route]() // other stuff } And Route: enum Route: Identifiable { var id: UUID { UUID() } case newTypeSelect case newEntityDetails(String) } extension Route: View { var body: some View { switch self { case .newTypeSelect: SelectTypeView() case .newEntityDetails(let type): NewEntityView(selectedType: type) } } } The menus show up fine but tapping on an item does nothing. I've attempted to wrap the menu in its own NavigationStack but that is rejected stating it is already in one defined by a parent view. I've tried making the links Buttons with destinations and those are also rejected. What is the newest/best way to present a menu with NavigationLinks? One doesn't simply wrap the menu in a NavigationView if one is using a NavigationStack?
1
0
865
Aug ’23
SwiftUI PhotosPicker - AXRuntimeError and detached view controller warning
I have the following code in a View that I show via a NavigationStack path.push() statement: @State private var avatarItem: PhotosPickerItem? @State private var avatarImage: Image? var body: some View { VStack(alignment: .center) { VStack { if let avatarImage { avatarImage .resizable() .frame(width: 200, height: 250) .foregroundColor(.gray) .padding() } else { Image("profile") .resizable() .frame(width: 200, height: 200) .foregroundColor(.gray) .padding() } PhotosPicker(selection: $avatarItem) { Label("Select a Photo", systemImage: "photo.artframe") } .padding() // process a selected image from the photo library .onChange(of: avatarItem) { newValue in Task { if let imageData = try? await newValue?.loadTransferable(type: Data.self), let image = UIImage(data: imageData) { avatarImage = Image(uiImage: image) } } } etc... It works and the selected image is displayed properly, but the console shows the following errors (plural): 2023-08-07 15:48:48.165282-0600 xxxapp[5190:599015] [AXRuntimeCommon] AX Lookup problem - errorCode:1100 error:Permission denied portName:'com.apple.iphone.axserver' PID:5199 ( 0 AXRuntime 0x00000001d37ccacc _AXGetPortFromCache + 968 1 AXRuntime 0x00000001d37cf038 AXUIElementPerformFencedActionWithValue + 852 2 UIKit 0x0000000232cf1ef0 4FEFF55E-05A3-3C88-9310-3F5FA9CFE3CD + 790256 3 libdispatch.dylib 0x00000001026b4520 _dispatch_call_block_and_release + 32 4 libdispatch.dylib 0x00000001026b6038 _dispatch_client_callout + 20 5 libdispatch.dylib 0x00000001026be0b0 _dispatch_lane_serial_drain + 984 6 libdispatch.dylib 0x00000001026bedf4 _dispatch_lane_invoke + 412 7 libdispatch.dylib 0x00000001026cbc74 _dispatch_workloop_worker_thread + 736 8 libsystem_pthread.dylib 0x00000002084c4ddc _pthread_wqthread + 288 9 libsystem_pthread.dylib 0x00000002084c4b7c start_wqthread + 8 This view is a couple of levels into my NavigationStack. I've toyed with moving some of the logic into the main thread, but that has not helped. The error 2023-08-07 15:58:40.433125-0600 xxxapp[5264:603960] [AXRuntimeCommon] Unknown client: xxxapp appears when the PhotoPicker is tapped and displayed, the rest when it returns. I also get a detached view controller error when this view is displayed, is that related? (Haven't figured that one out, yet, early days.) 2023-08-07 15:58:40.199165-0600 xxxapp[5264:603580] [Presentation] Presenting view controller <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x10602c800> from detached view controller <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x105824400> is discouraged. I'm using Xcode 14.3.1, target of iOS 16.4. The AXRuntime errors only appears on-device (iPhone XS Max), not in the simulator. I have also tried making this run on the main thread, no change. TIA!
0
0
532
Aug ’23