iPados上的Swiftui-多任务不显示正确的导航标题

发布于 2025-01-21 18:33:39 字数 1952 浏览 2 评论 0 原文

这是在iPados 15.4上。我正在使用Xcode 13.3.1。我正在使用Swiftui。我有两个文件:

ipadNavigationViewTestApp.swift

@main
struct iPadNavigationViewTestApp: App {
    var body: some Scene {
        WindowGroup {
            NavigationView {
                List {
                    NavigationLink(destination: ContentView()) {
                        Text("Content View 1")
                    }
                    
                    NavigationLink(destination: AnotherContentView()) {
                        Text("Content View 2")
                    }
                    
                    NavigationLink(destination: YetAnotherContentView()) {
                        Text("Content View 3")
                    }
                }
                .listStyle(.sidebar)
                .navigationTitle("This is a test")
                
                ContentView()
            }
        }
    }
}

contentView.swift

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
            .navigationTitle("ContentView")
    }
}

struct AnotherContentView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
            .navigationTitle("AnotherContentView")
    }
}

struct YetAnotherContentView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
            .navigationTitle("YetAnotherContentView")
    }
}

在iPad的多任务接口中,视图标题未正确显示:

在模拟器中,我使用侧边栏切换到第二视图,详细信息视图的导航标题更改为“另一个ContentView”。然而,多任务上的视图标题仍然是“ contentview”。我该如何显示正确的标题?这是Swiftui的错误吗?

This is on iPadOS 15.4. I'm using Xcode 13.3.1. I'm using SwiftUI. I have two files:

iPadNavigationViewTestApp.swift

@main
struct iPadNavigationViewTestApp: App {
    var body: some Scene {
        WindowGroup {
            NavigationView {
                List {
                    NavigationLink(destination: ContentView()) {
                        Text("Content View 1")
                    }
                    
                    NavigationLink(destination: AnotherContentView()) {
                        Text("Content View 2")
                    }
                    
                    NavigationLink(destination: YetAnotherContentView()) {
                        Text("Content View 3")
                    }
                }
                .listStyle(.sidebar)
                .navigationTitle("This is a test")
                
                ContentView()
            }
        }
    }
}

ContentView.swift

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
            .navigationTitle("ContentView")
    }
}

struct AnotherContentView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
            .navigationTitle("AnotherContentView")
    }
}

struct YetAnotherContentView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
            .navigationTitle("YetAnotherContentView")
    }
}

In the multitasking interface of iPad, the title of the view was not shown correctly:

iPad multitasking not showing title correctly

In the simulator I switched to the second view using the sidebar, and the detail view's navigation title changed to "AnotherContentView". Yet the view title on multitasking is still "ContentView". How do I let it show the correct title? Is this a bug of SwiftUI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文