gpt4 book ai didi

swiftui - 替代已弃用的PresentationLink? (Xcode 11 测试版 4)

转载 作者:行者123 更新时间:2023-12-02 15:51:18 25 4
gpt4 key购买 nike

在 Xcode beta 4 中,使用PresentationLink 会发出以下警告:“'PresentationLink' 已弃用:请改用 .sheet 修饰符。”

我假设它们是指某种形式的

func sheet<Content>(isPresented: Binding<Bool>, onDismiss: (() -> Void)? = nil, content: @escaping () -> Content) -> some View where Content : View

但我不确定如何切换到这个 - 特别是 isPresented 参数让我感到困惑。我知道有一个名为 isPresented 的环境变量,但这不是当前 View 的环境变量,而不是即将呈现的 View 吗?

我对此最感兴趣,因为我希望这能够解决PresentationLinks仅工作一次的问题(请参阅swiftUI PresentaionLink does not work second time)

既然PresentationLink已被弃用,任何人都可以提供一个简单的示例来说明如何呈现 View 吗?例如,将以下内容转换为使用 .sheet 修饰符:

  NavigationView {
List {
PresentationLink(destination: Text("Destination View")) {
Text("Source View")
}
}
}

最佳答案

下面是一个与您的示例最接近的示例。

import SwiftUI

struct Testing : View {
@State var isPresented = false

var body: some View {
NavigationView {
List {
Button(action: { self.isPresented.toggle() })
{ Text("Source View") }
}
}.sheet(isPresented: $isPresented, content: { Text("Destination View") })
}
}

这似乎确实解决了您提到的有关 PresentationLinks not working the second time 的错误

关于swiftui - 替代已弃用的PresentationLink? (Xcode 11 测试版 4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57084648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com