【问题标题】:NavigationView from actionSheet?来自actionSheet的NavigationView?
【发布时间】:2020-11-30 10:06:36
【问题描述】:

是否可以将 actionSheet 与 navigationView 一起使用?我想单击 actionSheet 中的按钮以将它们带到新视图。

                .actionSheet(isPresented: $showingActionSheet) {
                    ActionSheet(title: Text("Login"), message: Text("Choose how to login"), Buttons: [
                        .default(Text("Email and Password")) {
                        //Navigate somewhere using NavigationView
                        }

编辑:被告知要这样做,但仍然无法正常工作

                    .actionSheet(isPresented: $showingSheet) {
                    ActionSheet(title: Text("Login With:"), message: Text("Choose how to login"), buttons: [
                        .default(Text("Email")) { self.navigateTo = "emaillogin" },
                        .default(Text("QR Code")) { self.navigateTo = "QR" },
                        .default(Text("Key")) { self.navigateTo = "keylogin" },
                        .default(Text("Text")) { self.navigateTo = "textlogin" },
                        .cancel()
                    ])
                }
                .background(
                    NavigationLink(destination: Text(self.navigateTo), isActive: $isActive) {
                        EmptyView();
                    })

【问题讨论】:

标签: swift swiftui


【解决方案1】:

我在这里做错了吗?还是不行

好像错过了链接激活:

.actionSheet(isPresented: $showingSheet) {
    ActionSheet(title: Text("Login With:"), message: Text("Choose how to login"), buttons: [
        .default(Text("Email")) { self.navigateTo = "emaillogin"; isActive = true },
        .default(Text("QR Code")) { self.navigateTo = "QR"; isActive = true },
        .default(Text("Key")) { self.navigateTo = "keylogin"; isActive = true },
        .default(Text("Text")) { self.navigateTo = "textlogin"; isActive = true },
        .cancel()
    ])
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-13
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    • 2016-05-12
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多