【问题标题】:Unresolved identifier NavigationButton error未解决的标识符 NavigationButton 错误
【发布时间】:2019-08-22 18:52:18
【问题描述】:

我是 swiftUI 的新手,只是想弄清楚基础知识。我只是想创建一个新视图和一个将移至该视图的按钮。

当我使用下面的代码时,会出现一个错误:“使用未解析的标识符'NavigationButton'”,尽管它是由 Xcode 生成的。

import SwiftUI

struct HomeView: View {

    var body: some View{
        NavigationView {
            NavigationButton(destination: NextView()) {
                Text("Navigate 1")}
        }
    }
}

【问题讨论】:

    标签: ios swift xcode swiftui xcode11


    【解决方案1】:

    NavigationButton 暂时更改为NavigationLink。所以更换它并使用它。

    【讨论】:

      【解决方案2】:

      NavigationLink替换NavigationButton,下面的代码是WWDC 2019的更新Introducing SwiftUI: Building Your First App

      struct RoomCell: View {
          let room: Room
      
          var body: some View {
              NavigationLink(destination: RoomDetail(room: room)) {
                  Image(room.thumbnailName)
                      .cornerRadius(8)
                  VStack(alignment: .leading) {
                      Text(room.name)
                      Text("\(room.capacity) people")
                          .font(.subheadline)
                          .foregroundColor(.secondary)
                  }
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2016-10-08
        • 1970-01-01
        • 2019-05-01
        • 1970-01-01
        • 2018-12-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-10
        相关资源
        最近更新 更多