ios - swift Playground : get ViewController to call presentViewController

标签 ios xcode xcode7 uialertcontroller swift-playground

我想在 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

结果: UIAlertController on timeline

关于ios - swift Playground : get ViewController to call presentViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34693276/

相关文章:

iphone - 如何使用 didFinishPickingMediaWithInfo 从视频中查找 "Selected frames"的开始和结束持续时间?

iphone - 当我设置值和 forKey 时,iOS NSMutabledictionary 为空

ios - 社交框架 iOS 8 swift

ios - 如何在一个 ViewController 中创建实现多协议(protocol)?

ios - 奇怪的 Swift 2 Bug,源代码位于单独文件中时崩溃

objective-c - 检查一个点是否落在地理围栏内?

ios - xCode 8,swift 3,使用 LoginManager 的 Facebook SDK 登录必须点击两次才能打开 FB 登录表单

ios - 使用具有不同资源文件夹的 Xcode 构建 iOS 项目

swift - ECSlidingViewController 2 不工作 XCode 7 iOS 9

ios - 迪尔德 : Symbol not found: ___NSDictionary0__ when using google ServiceGenerator binary with discovery docs in XCode 7 & iOS target 9. 0