我想在 Playground 中使用 UIAlertController。是否可以从 XCPlaygroundPage 获取 ViewController - 以便能够调用 presentViewController?
最佳答案
您可以在呈现后将 liveView 设置为您的窗口,以避免出现警告。
import UIKit
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let window = UIWindow()
let viewController = UIViewController()
window.rootViewController = viewController
window.makeKeyAndVisible()
let alert = UIAlertController(title: "title here", message: "message here", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "action here", style: .default, handler: nil))
viewController.present(alert, animated: true, completion: nil)
PlaygroundPage.current.liveView = window
关于ios - swift Playground : get ViewController to call presentViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34693276/