te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>ios - SplitView is crashing iPad when specific Tab is selected and Sidebar is visible - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - SplitView is crashing iPad when specific Tab is selected and Sidebar is visible - Stack Overflow

programmeradmin4浏览0评论

I am using the new iOS 18 TabView with TabSection and Tab as child views. The main deployment for my app is iPad so it is critical that this works properly.

When the iPad is landscape, I should be able to Split View and display another app alongside - so long as "Requires Full Screen" is set to NO in info.plist.

For the most part I can do this. And when I remove the TabSections from the TabView the problem goes away. But I must keep the TabSections as my actual app has 14 Tabs and there seems to be a limit on standalone Tabss. So as it stands, for just two of my views, there is some very random and strange behaviour.

In my very simple min reproducible example below, when the iPad is landscape and the sidebar is hidden (only the menu across the top is visible) I can successfully run Split View for ALL of the Tabs in my list. Whenever the sidebar is displayed (which would be the standard landscape setup) and my "Location Brief" or "Restricted Area Brief" Tabs are selected, the app crashes. So the issue I believe is with the sidebar, as I get this error:

SwiftUI/SidebarAdaptableTabViewStyle_iOS.swift:482: Fatal error: Tried to update with invalid selection value

The sidebar also seems to be "sticky" with the highlight of the "Location Brief" in its menu too, where selecting it first and then selecting "Area Brief" changes the Content View but doesn't change the selection in the sidebar menu....

Another issue is that when in Split View with the "NOTAM" Tab active and the split is 50/50 or greater, narrowing the view to less than this will switch to "Area Brief".

I must keep Split View an option for this app, and I must have a sidebar visible for landscape operation.

I have tried to closely follow Apple's documentation and have looked at lots of forums etc. but I still get the issue. What can I try next?

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

import SwiftUI

@main
struct scrapAppApp: App {
    var body: some Scene {
        WindowGroup {
            MenuView()
        }
    }
}

.

import SwiftUI

struct MenuView: View {
    
    @AppStorage("MyAppTabViewCustomization")
    private var customization: TabViewCustomization
    
    @State private var selectedTab: Tabs?
    
    enum Tabs: String, Hashable, CaseIterable {
        case planner, plan, weather, locationbrief, areabrief, additional, notam, restrictedBrief, appSettings, settings
        
        var customizationID: String {
            rawValue
        }
    }
    
    var body: some View {
        TabView(selection: $selectedTab) {
            TabSection("Planner") {
                
                Tab("Plan", systemImage: "paperplane", value: Tabs.plan) {
                    Text("Plan")
                }.customizationID(Tabs.plan.customizationID)
            }.customizationID(Tabs.planner.customizationID)
            
            
            TabSection("Weather") {
                
                Tab("Location Brief", systemImage: "mappin.square", value: Tabs.locationbrief) {
                    Text("Location Brief") // this crashes ..........................
                }.customizationID(Tabs.locationbrief.customizationID)
                
                Tab("Area Brief", systemImage: "map", value: .areabrief) {
                    Text("Area Brief")
                }.customizationID(Tabs.areabrief.customizationID)

            }.customizationID(Tabs.weather.customizationID)
            
            
            TabSection("Additional") {
                
                Tab("NOTAM", systemImage: "text.document", value: Tabs.notam) {
                    Text("NOTAM")
                }.customizationID(Tabs.notam.customizationID)
                
                Tab("Restricted Area Brief", systemImage: "xmark.seal", value: .restrictedBrief) {
                    Text("Restricted Area Brief") // this crashes ..........................
                }.customizationID(Tabs.restrictedBrief.customizationID)
                
            }.customizationID(Tabs.additional.customizationID)
            
            
            TabSection("App Settings") {
                
                Tab("Settings", systemImage: "gear", value: Tabs.settings) {
                    Text("Settings")
                }.customizationID(Tabs.settings.customizationID)
                
            }.customizationID(Tabs.appSettings.customizationID)
        }
        .tabViewStyle(.sidebarAdaptable)
        .tabViewCustomization($customization)
    }
}

#Preview {
    MenuView()
}

I am using the new iOS 18 TabView with TabSection and Tab as child views. The main deployment for my app is iPad so it is critical that this works properly.

When the iPad is landscape, I should be able to Split View and display another app alongside - so long as "Requires Full Screen" is set to NO in info.plist.

For the most part I can do this. And when I remove the TabSections from the TabView the problem goes away. But I must keep the TabSections as my actual app has 14 Tabs and there seems to be a limit on standalone Tabss. So as it stands, for just two of my views, there is some very random and strange behaviour.

In my very simple min reproducible example below, when the iPad is landscape and the sidebar is hidden (only the menu across the top is visible) I can successfully run Split View for ALL of the Tabs in my list. Whenever the sidebar is displayed (which would be the standard landscape setup) and my "Location Brief" or "Restricted Area Brief" Tabs are selected, the app crashes. So the issue I believe is with the sidebar, as I get this error:

SwiftUI/SidebarAdaptableTabViewStyle_iOS.swift:482: Fatal error: Tried to update with invalid selection value

The sidebar also seems to be "sticky" with the highlight of the "Location Brief" in its menu too, where selecting it first and then selecting "Area Brief" changes the Content View but doesn't change the selection in the sidebar menu....

Another issue is that when in Split View with the "NOTAM" Tab active and the split is 50/50 or greater, narrowing the view to less than this will switch to "Area Brief".

I must keep Split View an option for this app, and I must have a sidebar visible for landscape operation.

I have tried to closely follow Apple's documentation and have looked at lots of forums etc. but I still get the issue. What can I try next?

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

import SwiftUI

@main
struct scrapAppApp: App {
    var body: some Scene {
        WindowGroup {
            MenuView()
        }
    }
}

.

import SwiftUI

struct MenuView: View {
    
    @AppStorage("MyAppTabViewCustomization")
    private var customization: TabViewCustomization
    
    @State private var selectedTab: Tabs?
    
    enum Tabs: String, Hashable, CaseIterable {
        case planner, plan, weather, locationbrief, areabrief, additional, notam, restrictedBrief, appSettings, settings
        
        var customizationID: String {
            rawValue
        }
    }
    
    var body: some View {
        TabView(selection: $selectedTab) {
            TabSection("Planner") {
                
                Tab("Plan", systemImage: "paperplane", value: Tabs.plan) {
                    Text("Plan")
                }.customizationID(Tabs.plan.customizationID)
            }.customizationID(Tabs.planner.customizationID)
            
            
            TabSection("Weather") {
                
                Tab("Location Brief", systemImage: "mappin.square", value: Tabs.locationbrief) {
                    Text("Location Brief") // this crashes ..........................
                }.customizationID(Tabs.locationbrief.customizationID)
                
                Tab("Area Brief", systemImage: "map", value: .areabrief) {
                    Text("Area Brief")
                }.customizationID(Tabs.areabrief.customizationID)

            }.customizationID(Tabs.weather.customizationID)
            
            
            TabSection("Additional") {
                
                Tab("NOTAM", systemImage: "text.document", value: Tabs.notam) {
                    Text("NOTAM")
                }.customizationID(Tabs.notam.customizationID)
                
                Tab("Restricted Area Brief", systemImage: "xmark.seal", value: .restrictedBrief) {
                    Text("Restricted Area Brief") // this crashes ..........................
                }.customizationID(Tabs.restrictedBrief.customizationID)
                
            }.customizationID(Tabs.additional.customizationID)
            
            
            TabSection("App Settings") {
                
                Tab("Settings", systemImage: "gear", value: Tabs.settings) {
                    Text("Settings")
                }.customizationID(Tabs.settings.customizationID)
                
            }.customizationID(Tabs.appSettings.customizationID)
        }
        .tabViewStyle(.sidebarAdaptable)
        .tabViewCustomization($customization)
    }
}

#Preview {
    MenuView()
}
Share Improve this question edited 2 days ago HangarRash 15.1k5 gold badges19 silver badges55 bronze badges asked 2 days ago PW1990PW1990 4792 silver badges11 bronze badges 4
  • 1 FYI, could not replicate any crash, but can see the other issues. Note, not relevant but you are missing Tabs. eg for .restrictedBrief and .areabrief. – workingdog support Ukraine Commented 2 days ago
  • Thank you, so you think there is an issue in my info.plist or some kind of other issue with my deployment? When you do run it, please have the ipad sim in landscape and select Location Brief from the side menu, then run split view and it should crash. Same goes with Restricted Area Brief, the sidebar menu must be displayed for the crash to occur. Are you running the same versions as me? Also, I saw that Tabs. was only needed in the first item inside the TabSection but thank you, I will add those in. – PW1990 Commented 2 days ago
  • I don't know where the problem is, sorry. I'm on macOS 15.3.1, using Xcode 16.2, target iOS-18.2, tested on real iPad device, just updated to iOS-18.3.1. – workingdog support Ukraine Commented 2 days ago
  • Ok, I have updated all my software to be the same as yours now and tried on real iPad too but I still get the same crashes. Can you think of maybe something in the info.plist that could cause this issue? I am so confused still. Appreciate the help – PW1990 Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 0

I have a potential source of the error and have been able to iron out almost all of the issues by retaining only 1 TabSection and leaving all others as a standalone Tab.

So for anyone with the same issue, it seems that multiple TabSections cause this problem.

Crashes are resolved completely and when within a standalone Tab the resizing of the Split View doesn't switch between views. This switching does however still occur with Tabs within the TabSection.

发布评论

评论列表(0)

  1. 暂无评论