P5m*_*sic 2 xcode closures menu ios swiftui
我正在使用 SwiftUI 创建 iOS 应用程序
\n我使用了主/详细模板并得到了这个:
\nstruct ContentView: View {\n\nvar body: some View {\n \n NavigationView {\n \n if (conditionsForMasterDetail)\n {\n masterView\n .navigationBarTitle(Text("Master"))\n .navigationBarItems(\n leading: EditButton(),\n trailing: Button(\n action: {\n withAnimation { self.dates.insert(Date(), at: 0) }\n }\n ) {\n Image(systemName: "plus")\n }\n )\n }\n \n if (conditionsForDetaiView)\n {\n detailView\n }\n } //NavigationView\n .navigationViewStyle(DoubleColumnNavigationViewStyle()).toolbar {\n ToolbarItem(placement: .primaryAction) {\n Menu\n { //error here: \xe2\x80\x9cTrailing closure passed to parameter of type 'MenuStyleConfiguration' that does not accept a closure\xe2\x80\x9d \n NavigationLink(destination:HelpView(appData: appData))\n { Button(action: {}) {\n Label(help_menu_item, systemImage: "")\n }\n }\n Button(action: {}) {\n Label(liability_disclaimer_menu_item, systemImage: "")\n }\n \n Button(action: {}) {\n Label(R.string.about_menu_item, systemImage: "")\n }\n \n\n \n \n }//menu\n \n label: {//error here: Extra argument 'label' in call\n Label("Menu", systemImage: "")\n }\n \n }//toolbar item\n \n \n}//toolbar\n\n} //body\n} //ContentView\nRun Code Online (Sandbox Code Playgroud)\n问题出在菜单上,因为发出了错误:
\nTrailing closure passed to parameter of type 'MenuStyleConfiguration' that does not accept a closure\nRun Code Online (Sandbox Code Playgroud)\n请注意,尾随闭包只是编写初始化器参数的不同方式。菜单似乎接受配置,但我看到内容和标签(标签上的错误:调用中的额外参数“标签”)。
\n我尝试了各种不使用尾随闭包语法编写 init 的方法,但它不会产生工作代码。
\n我想知道这是一个错误还是一个真正的错误。
\n这并没有具体回答这个问题,而是因为我找不到该主题的任何其他答案。
抛出同样的错误:
struct TextPopup: View {
var body: some View {
Menu {
Text("hello")
}
}
}
Run Code Online (Sandbox Code Playgroud)
正确编译:
struct TextPopup: View {
var body: some View {
Menu {
Text("hello")
} label: {}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5767 次 |
| 最近记录: |