尾随关闭失败的 SwiftUI 菜单 (MenuStyleConfiguration)

SwiftUI menu with failing trailing closure (MenuStyleConfiguration)

我正在使用 SwiftUI 创建一个 iOS 应用程序

我使用了 master/detail 模板并得到了这个:

struct ContentView: View {

var body: some View {
  
     NavigationView {
        
        if (conditionsForMasterDetail)
        {
          masterView
            .navigationBarTitle(Text("Master"))
            .navigationBarItems(
                leading: EditButton(),
                trailing: Button(
                    action: {
                        withAnimation { self.dates.insert(Date(), at: 0) }
                    }
                ) {
                    Image(systemName: "plus")
                }
            )
        }
        
        if (conditionsForDetaiView)
        {
          detailView
        }
        } //NavigationView
    .navigationViewStyle(DoubleColumnNavigationViewStyle()).toolbar {
        ToolbarItem(placement: .primaryAction) {
            Menu
            { //error here: “Trailing closure passed to parameter of type 'MenuStyleConfiguration' that does not accept a closure”                        
                    NavigationLink(destination:HelpView(appData: appData))
                                        {                        Button(action: {}) {
                        Label(help_menu_item, systemImage: "")
                    }
                    }
                    Button(action: {}) {
                        Label(liability_disclaimer_menu_item, systemImage: "")
                    }
                
                                       Button(action: {}) {
                        Label(R.string.about_menu_item, systemImage: "")
                    }
                    

                
                
            }//menu
             
                 label: {//error here: Extra argument 'label' in call
        Label("Menu", systemImage: "")
    }
         
    }//toolbar item
         
           
}//toolbar

} //body
} //ContentView

问题出在菜单上,因为发出错误:

Trailing closure passed to parameter of type 'MenuStyleConfiguration' that does not accept a closure

请注意,尾随闭包只是编写初始化程序参数的一种不同方式。菜单似乎接受配置,但我看到了内容和标签(标签错误:调用中的额外参数 'label')。

我尝试了各种不带尾随闭包语法的 init 编写方法,但它不会导致工作代码。

我想知道这是一个错误还是一个真正的错误。

这是用 Xcode 12 / iOS 14 编译好的快照,以某种方式清理复制。您可以将您的细节一一注入。

注意:NavigationLink中的Button不起作用,所以没有意义(因为NavigationLink本身就是一个按钮)

struct ContentView: View {
    @State private var conditionsForMasterDetail = false
    @State private var conditionsForDetaiView = false

    var body: some View {
        NavigationView {
            if (conditionsForMasterDetail)
            {
                Text("masterView")
                    .navigationBarTitle(Text("Master"))
                    .navigationBarItems(
                        leading: EditButton(),
                        trailing: Button(
                            action: {
                                withAnimation { /*self.dates.insert(Date(), at: 0)*/ }
                            }
                        ) {
                            Image(systemName: "plus")
                        }
                    )
            }

            if (conditionsForDetaiView)
            {
                Text("detailView")
            }
        } //NavigationView
        .navigationViewStyle(DoubleColumnNavigationViewStyle()).toolbar {
            ToolbarItem(placement: .primaryAction) {
                Menu
                {
                    NavigationLink(destination:Text("HelpView(appData: appData)"))
                    { Text("Link")
                        //                        Label(help_menu_item, systemImage: "")
                    }
                    Button(action: {}) {
                        Text("A")
                        //                        Label(liability_disclaimer_menu_item, systemImage: "")
                    }

                    Button(action: {}) {
                        Text("B")
                        //                        Label(R.string.about_menu_item, systemImage: "")
                    }
                }//menu

                label: {//error here: Extra argument 'label' in call
                    Label("Menu", systemImage: "")
                }
            }//toolbar item
        }//toolbar
    } //body
} //ContentView

这并没有具体回答这个问题,而是因为我找不到这个主题的任何其他答案。

抛出同样的错误:

struct TextPopup: View {
    var body: some View {
        Menu {
            Text("hello")
        }
    }
}

正确编译:

struct TextPopup: View {
    var body: some View {
        Menu {
            Text("hello")
        } label: {}
    }
}