1.1 C
New York
Sunday, February 23, 2025

ios – SplitView is crashing iPad when particular Tab is chosen and Sidebar is seen


I’ve spent the final a number of days attempting totally different fixes and on the lookout for solutions to this, frustratingly to no avail.

I’m utilizing the brand new iOS 18 TabView with TabSection and Tab as youngster views. The primary deployment for my app is iPad so it’s vital that this works correctly.

When the iPad is panorama, I ought to be capable of Cut up View and show one other app alongside – as long as “Requires Full Display” is about to NO in data.plist.

For probably the most half I can do that…And after I take away the TabSections from the TabView the issue goes away. However I have to preserve the TabSections as my precise app has 14 Tabs and there appears to be a restrict on standalone Tabss. In order it stands, for simply two of my views, there may be some very random and unusual behaviour.

In my quite simple min reproducible instance under, when the iPad is panorama and the sidebar is hidden (solely the menu throughout the highest is seen) I can efficiently run Cut up View for ALL of the Tabs in my record. Each time the sidebar is displayed (which might be the usual panorama setup) and my “Location Temporary” or “Restricted Space Temporary” Tabs are chosen, the app crashes. So the problem I consider is with the sidebar, as I get this error:

SwiftUI/SidebarAdaptableTabViewStyle_iOS.swift:482: Deadly error: Tried to replace with invalid choice worth

The sidebar additionally appears to be “sticky” with the spotlight of the “Location Temporary” in its menu too, the place deciding on it first after which deciding on “Space Temporary” modifications the Content material View however does not change the choice within the sidebar menu….

One other situation is that when in Cut up View with the “NOTAM” Tab energetic and the break up is 50/50 or higher, narrowing the view to lower than this may change to “Space Temporary”…

I’m clearly doing one thing fallacious or have left one thing vital out.

I have to preserve Cut up View an choice for this app, and I will need to have a sidebar seen for panorama operation.

I’ve tried to intently comply with Apple’s documentation and have checked out numerous boards and many others. however I nonetheless get the problem.

Any assist could be tremendously appreciated with this as I’m completely caught right here and it’s tremendous irritating.

Min deployment iOS 18, Simulator is operating 18.2, Swift 16.2

import SwiftUI

@essential
struct scrapAppApp: App {
    var physique: some Scene {
        WindowGroup {
            MenuView()
        }
    }
}

.

import SwiftUI

struct MenuView: View {
    
    @AppStorage("MyAppTabViewCustomization")
    personal var customization: TabViewCustomization
    
    @State personal var selectedTab: Tabs?
    
    enum Tabs: String, Hashable, CaseIterable {
        case planner, plan, climate, locationbrief, areabrief, further, notam, restrictedBrief, appSettings, settings
        
        var customizationID: String {
            rawValue
        }
    }
    
    var physique: some View {
        TabView(choice: $selectedTab) {
            TabSection("Planner") {
                
                Tab("Plan", systemImage: "paperplane", worth: Tabs.plan) {
                    Textual content("Plan")
                }.customizationID(Tabs.plan.customizationID)
            }.customizationID(Tabs.planner.customizationID)
            
            
            TabSection("Climate") {
                
                Tab("Location Temporary", systemImage: "mappin.sq.", worth: Tabs.locationbrief) {
                    Textual content("Location Temporary") // this crashes ..........................
                }.customizationID(Tabs.locationbrief.customizationID)
                
                Tab("Space Temporary", systemImage: "map", worth: .areabrief) {
                    Textual content("Space Temporary")
                }.customizationID(Tabs.areabrief.customizationID)

            }.customizationID(Tabs.climate.customizationID)
            
            
            TabSection("Further") {
                
                Tab("NOTAM", systemImage: "textual content.doc", worth: Tabs.notam) {
                    Textual content("NOTAM")
                }.customizationID(Tabs.notam.customizationID)
                
                Tab("Restricted Space Temporary", systemImage: "xmark.seal", worth: .restrictedBrief) {
                    Textual content("Restricted Space Temporary") // this crashes ..........................
                }.customizationID(Tabs.restrictedBrief.customizationID)
                
            }.customizationID(Tabs.further.customizationID)
            
            
            TabSection("App Settings") {
                
                Tab("Settings", systemImage: "gear", worth: Tabs.settings) {
                    Textual content("Settings")
                }.customizationID(Tabs.settings.customizationID)
                
            }.customizationID(Tabs.appSettings.customizationID)
        }
        .tabViewStyle(.sidebarAdaptable)
        .tabViewCustomization($customization)
    }
}

#Preview {
    MenuView()
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles