简体   繁体   English

SwiftUI 导航栏标题

[英]SwiftUI Navigation Bar Title

I'm making my very first steps into SwiftUI following HackingWithSwift course.在 HackingWithSwift 课程之后,我迈出了进入 SwiftUI 的第一步。 Did face a problem trying to implement Navigation bar in my app.尝试在我的应用程序中实现导航栏时确实遇到了问题。 For some reasons, the title of Navigation bar does not show up.由于某些原因,导航栏的标题不显示。 Here's the code I'm using:这是我正在使用的代码:

struct ContentView: View {
    var body: some View {
        NavigationView {
            Form {
                ...
            }
        }
        .navigationBarTitle(Text("WeSplit"))
    }
}

Once running it in simulator or on my target device I see free space for the navigation bar title but no text there.在模拟器或我的目标设备上运行它后,我会看到导航栏标题的可用空间,但那里没有文本。

I've also tried typing .navigationBarTitle("WeSplit") with no Text() in there.我也尝试输入.navigationBarTitle("WeSplit") ,其中没有 Text() 。 Result's still the same.结果还是一样。

Do you have any ideas on how to fix it?您对如何解决它有任何想法吗? Thank you in advance!先感谢您!

I'm running Xcode Version 12.3.我正在运行 Xcode 版本 12.3。

It should be inside NavigationView , like它应该在NavigationView里面,比如

struct ContentView: View {
    var body: some View {
        NavigationView {
            Form {
                ...
            }
            .navigationBarTitle(Text("WeSplit"))     // << here !!
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM