如何在Swift游乐场中获得弹出对话框
我想知道如何在Swift操场中弹出一个对话框(是的,必须在操场中)。我已经尝试了以下代码(直接从AppleDevs站点) 但是,无论我怎么做,如何在Swift游乐场中获得弹出对话框,swift,swift-playground,Swift,Swift Playground,我想知道如何在Swift操场中弹出一个对话框(是的,必须在操场中)。我已经尝试了以下代码(直接从AppleDevs站点) 但是,无论我怎么做,selftag总是会抛出一个错误。有人能帮我吗 import UIKit let alert = UIAlertController(title: "My Alert", message: "This is an alert.", preferredStyle: .alert) alert.addAction(UIAlertAction(title: N
self
tag总是会抛出一个错误。有人能帮我吗
import UIKit
let alert = UIAlertController(title: "My Alert", message: "This is an alert.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in
NSLog("The \"OK\" alert occured.")
}))
self.present(alert, animated: true, completion: nil)
需要从视图控制器显示警报。这意味着它将出现在助理编辑器内的模拟器中: 例如:
import UIKit
import PlaygroundSupport
let alert = UIAlertController(title: "My Alert", message: "This is an alert.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in
NSLog("The \"OK\" alert occured.")
}))
let v = UIViewController()
PlaygroundPage.current.liveView = v
v.present(alert, animated: true, completion: nil)
创建游乐场文件时选择单一视图在哪里?“单一视图”在任何地方都没有列出