【问题标题】:PresentationButton didn't trigger action twicePresentationButton 没有触发两次动作
【发布时间】:2019-06-05 12:55:11
【问题描述】:

我想呈现模态视图并在关闭后再次呈现它。

struct ContentView : View {
    var body: some View {
        NavigationView {
            Group {
                Text("hi")
                Text("hello")
                }
                .navigationBarItem(title: Text("Demo"))
                .navigationBarItems(trailing:
                    PresentationButton(
                        Image(systemName: "person.crop.circle")
                            .imageScale(.large)
                            .accessibility(label: Text("User Profile"))
                            .padding(),
                        destination: Text("User Profile")
                    )
            )
        }
    }
}

它仅在第一次点击时触发。关闭目标视图后,点击PresentationButton 什么也不做。有人对此有解决方案吗?

【问题讨论】:

  • 这对我来说似乎是一个错误。它也对我不起作用。希望有人(WWDC 参加者)在 SwiftUI 实验室期间与 Apple 人员进行检查。
  • @SMP 你知道我们应该在某个地方填写问题吗?
  • 也有这个问题。更奇怪的是,我的演示按钮上方还有另一个按钮,在第一次单击演示按钮后,上面的按钮接管了演示按钮的操作。
  • @apocolipse 我在两个平台(catalina 和 mojave)上都有问题
  • 我有同样的问题,即使是从苹果开发者网站下载的教程项目。绝对是一个错误

标签: ios swift swiftui


【解决方案1】:

它看起来像一个错误,这里有一个解决方法:

struct ContentView : View {

    @State var showModal: Bool = false

    var body: some View {
        NavigationView {
            Group {
                Text("hi")
                Text("hello")
            }
            .navigationBarItem(title: Text("Demo"))
            .navigationBarItems(trailing:
                Button(action: {
                    self.showModal = true
                }) {
                    Image(systemName: "person.crop.circle")
                }
            )
            }.presentation(showModal ? Modal(Text("Hey"),
                                             onDismiss: { self.showModal = false }) : nil)
    }
}

【讨论】:

    猜你喜欢
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 2021-02-13
    • 2013-01-02
    • 2018-10-28
    相关资源
    最近更新 更多