[英]using navigation links xcode swift IOS 16
Hello I am trying to use a simple navigation link but it seems like this method has been depreciated with this new IOS update.您好,我正在尝试使用一个简单的导航链接,但似乎此方法已因新的 IOS 更新而贬值。 I tried looking at the apple doc to try and fix it but im not sure how.
我试着查看苹果文档来尝试修复它,但我不确定如何修复。 I get the following error "depreciated in IOS 16: use NavigationLink(value:label:) inside a navigationStack or NavigationSplitView" I will also add my code below.
我收到以下错误“在 IOS 16 中折旧:在 navigationStack 或 NavigationSplitView 中使用 NavigationLink(value:label:)”我还将在下面添加我的代码。 Anyone know how to format it correctly?
任何人都知道如何正确格式化它?
@EnvirnmentObject var viewModel: AuthViewModel()
var body: some View {
NavigationLink(destination: ProfileView(), isActive:
$viewModel.user, label: {})
}
}
in iOS 16 Navigation was significantly changed.在 iOS 16 导航发生了重大变化。 If your Navigation looks like:
如果您的导航看起来像:
@State private var viewModel = ViewModel()
var body: some View {
NavigationView {
List {
NavigationLink("User name", isActive: $viewModel.user) {
UserDetail(user: viewModel.user)
}
}
}
.navigationViewStyle(.stack)
}
use instead改用
@State private var viewModel = ViewModel()
var body: some View {
NavigationStack {
List {
NavigationLink("User Name", value: user)
}
.navigationDestination(for: User.self) { user in
UserDetail(user: user)
}
}
}
You can find more detail in https://developer.apple.com/documentation/swiftui/migrating-to-new-navigation-types您可以在https://developer.apple.com/documentation/swiftui/migrating-to-new-navigation-types中找到更多详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.