【问题标题】:How to present an UIViewController in Swift Playgrounds for macOS?如何在 macOS 的 Swift Playgrounds 中呈现 UIViewController?
【发布时间】:2020-02-12 10:26:01
【问题描述】:

我在我的 macOS 设备上从 AppStore 下载了 Swift Playgrounds v3.2。我想在一个空项目中展示 UIViewController 类的一个实例。我试着用PlaygroundPage.current.liveView = vc 在 Xcode 操场上展示它,但它不起作用。

import PlaygroundSupport

let vc = UIViewController()

PlaygroundPage.current.liveView = vc

PlaygroundPage.current.needsIndefiniteExecution = true

【问题讨论】:

    标签: ios swift swift-playground


    【解决方案1】:

    确保你导入UIKit

    然后像这样设置 UIViewController 的视图为 liveView

    PlaygroundPage.current.liveView = vc.view
    

    【讨论】:

      猜你喜欢
      • 2015-10-20
      • 1970-01-01
      • 1970-01-01
      • 2019-04-02
      • 1970-01-01
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多