如何解决带有失败的结尾关闭的SwiftUI菜单MenuStyleConfiguration
我正在使用SwiftUI创建iOS应用
我使用了主/明细模板,然后转到了:
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
请注意,尾随闭包只是编写初始化程序参数的另一种方式。菜单似乎接受了配置,但是我看到了内容和标签(标签错误:调用中有额外的参数“标签”)。
我尝试了所有类型的init,但都没有尾随的闭包语法,但这并没有导致有效的代码。
我想知道这是一个错误还是一个真正的错误。
解决方法
这并没有专门回答这个问题,而是因为我找不到这个话题的任何其他答案。
抛出同样的错误:
struct TextPopup: View {
var body: some View {
Menu {
Text("hello")
}
}
}
正确编译:
struct TextPopup: View {
var body: some View {
Menu {
Text("hello")
} label: {}
}
}
,
这里可以通过某种方式清除复制的快照,这些快照可以使用Xcode 12 / iOS 14很好地编译。您可以一一注入自己的详细信息。
注意:Button
中的NavigationLink
不起作用,因此没有任何意义(因为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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。