Cod*_*ott 5 uiactionsheet swiftui
我想使用变量在视图中调用不同的操作表。这并不意味着工作。
.actionSheet(isPresented: self.$neuinitialisierung) {
ActionSheet(
title: Text("Testtitel 1"),
message: Text("Testmessage 1"),
buttons: [
.default(Text("Button 1"),
action: {
print("KLICK")
}),
.default(Text("Button 2"),
action: {
self.clouddienst_waehlen = true;
})
])
}
.actionSheet(isPresented: self.$clouddienst_waehlen) {
ActionSheet(
title: Text("Testtitel 2"),
message: Text("Testmessage 2"),
buttons: [
.default(Text("Button 1"),
action: {
print("KLICK")
}),
.default(Text("Button 2"),
action: {
self.clouddienst_waehlen = true;
})
])
}
Run Code Online (Sandbox Code Playgroud)
如果我只用一张动作表尝试它,它就会起作用。我怎样才能使用第二个?
不需要任何这些复杂的解决方案。只需将您的 .actionSheets 附加到不同的视图即可。它不需要\xe2\x80\x99 位于根级别。例如,您可以在按钮上使用 .actionSheet 修饰符。
\n您可以使用:
func actionSheet<T>(item: Binding<T?>, content: (T) -> ActionSheet) -> some View where T : Identifiable
Run Code Online (Sandbox Code Playgroud)
它需要绑定到某种可选类型,如果该值不为零,则显示一个 ActionSheet。您可以将此选项设置为某个值,而不是将标志设置为 true。
| 归档时间: |
|
| 查看次数: |
812 次 |
| 最近记录: |