以下代码在 iOS 和 Catalyst 上编译并运行得很好。但当我在 macOS 应用程序中运行它时,出现错误。这是一个已知的错误还是我做错了什么。macOS Catalina 版本 10.15.3,Xcode 版本 11.3.1。
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List {
Text("Item #1")
Text("Item #2")
}
.navigationBarTitle("Title", displayMode: .inline)
.navigationBarItems(leading: Text("Add"))
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误,
Value of type 'List<Never, TupleView<(Text, Text)>>' has no member 'navigationBarTitle'
标题栏在 macOS 上不可用。这是接口声明:
Run Code Online (Sandbox Code Playgroud)@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *) @available(OSX, unavailable) extension View { /// Hides the navigation bar for this view. /// /// This modifier only takes effect when this view is inside of and visible /// within a `NavigationView`. /// /// - Parameters: /// - hidden: A Boolean value that indicates whether to hide the /// navigation bar. @available(OSX, unavailable) public func navigationBarHidden(_ hidden: Bool) -> some View /// Configures the title in the navigation bar for this view. /// /// This modifier only takes effect when this view is inside of and visible /// within a `NavigationView`. /// /// - Parameters: /// - title: A description of this view to display in the navigation /// bar. @available(OSX, unavailable) public func navigationBarTitle(_ title: Text) -> some View /// Configures the title in the navigation bar for this view. /// /// This modifier only takes effect when this view is inside of and visible /// within a `NavigationView`. /// /// - Parameters: /// - titleKey: A key to a localized description of this view to display /// in the navigation bar. @available(OSX, unavailable) public func navigationBarTitle(_ titleKey: LocalizedStringKey) -> some View
| 归档时间: |
|
| 查看次数: |
4793 次 |
| 最近记录: |