ios - 如何在 macOS 的 Swift Playgrounds 中呈现 UIViewController?
问题描述
我在我的 macOS 设备上从 AppStore 下载了 Swift Playgrounds v3.2。我想在一个空项目中展示 UIViewController 类的一个实例。我试图像在 Xcode 操场上一样展示它,PlaygroundPage.current.liveView = vc
但它不起作用。
import PlaygroundSupport
let vc = UIViewController()
PlaygroundPage.current.liveView = vc
PlaygroundPage.current.needsIndefiniteExecution = true
解决方案
确保您导入UIKit
然后像这样将 UIViewController 的视图设置为 liveView
PlaygroundPage.current.liveView = vc.view
推荐阅读
- rust - 如何使用 log4rs 的 RollingFileAppender 来合并滚动日志?
- excel - 检查当前行单元格日期是否在过去
- javascript - 无法理解此 JSON 解析错误
- c# - DropDownList 允许设置 DataSource 但在 DataBind 处出错
- javascript - 在 Mocha 中的 Before Hook 之前执行 BeforeEach Hook
- javascript - document.execCommand() 方法不适用于 Iphone 中的 safari
- c - 用 C 计算
- java - 如何在 jenkinsfile 中将参数传递给 sbt
- javascript - 为什么 splice 方法只删除 React 中的第一个数组索引?
- c# - Asp.Net Core 3(Blazor 客户端)的构建失败