【问题标题】:SwiftUI PlaygroundBook I can't access the other ViewSwiftUI PlaygroundBook 我无法访问其他视图
【发布时间】:2021-04-11 14:39:09
【问题描述】:

我无法从 WelcomeView 访问 GameView。如何在 Playground Book 中获取页面导航?

错误

Cannot find "Game View" in scope

欢迎观看

import SwiftUI
import PlaygroundSupport

struct WelcomeView: View {
    var body: some View {
        GameView()
    }
}
PlaygroundPage.current.setLiveView(WelcomeView())

游戏视图

import SwiftUI
import PlaygroundSupport

struct GameView: View {
    var body: some View {
        Text("GameView")
    }
}
PlaygroundPage.current.setLiveView(GameView())

欢迎查看图片

游戏画面

【问题讨论】:

    标签: swiftui swift-playground


    【解决方案1】:

    您应该将public 访问级别添加到您的类/属性/方法/属性。有了它,您就可以从 ma​​in 游乐场访问它们。


    public struct GameView: View {
    
      public init() { }
    
      public var body: some View {
        Text("GameView")
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多