ios - 无法转换“NavigationLink”类型的值' 关闭结果类型 '_'
问题描述
我收到以下错误:
无法将“NavigationLink”类型的值转换为闭包结果类型“_”
你知道这里有什么问题吗?
我的内容视图文件:
@ObservedObject var voucherData = VoucherData()
var body: some View {
NavigationView {
ZStack {
List {
ForEach(voucherData.voucherList) { voucher in
NavigationLink(destination: EditView(value:voucher.value, currency: voucher.currency, shopName: voucher.shopName)) {
VStack() {
在另一个文件中:
struct Voucher : Identifiable {
let id = UUID()
var value : String = ""
var currency : String = ""
var shopName : String = ""
}
final class VoucherData: ObservableObject {
@Published var voucherList: [Voucher] = [
.init(value: "100", currency: "USD", shopName: "FlyBurger")]
}
解决方案
我假设您的 EditView 只是缺少参数凭证:
struct EditView: View {
let voucher: Voucher
...
}
现在您可以像这样传递凭证:
NavigationLink(destination: EditView(voucher: voucher)) {
推荐阅读
- r - 使用 withr::with_options 将 shiny.maxRequestSize 传递给闪亮的应用程序
- javascript - 创建 javascript 数组,其中每个元素都有一个可以引用其在新数组中的位置的函数
- c++ - 具有预分配结果 C++ 的重载加号运算符
- asp.net-mvc - ASP.NET - 视图中不同类型的三元运算符
- asp.net - 网站不会自动重定向到 adfs 登录
- sql - Laravel 查询错误
- javascript - 在 Heroku 上构建 create-react-app 失败
- c# - 将音频录制到内存流中,然后将其保存到文件中
- python - 使用 PyArrow 首次读取后无法写入 Parquet 文件
- amazon-web-services - 尝试使用 Amazon S3 CLI 复制一个文件