我想知道如何在Swift 游乐场中打开对话框(必须在游乐场中)我尝试了以下代码(直接从AppleDevs站点获取)
但是,无论我如何尝试,self
标记总是都会引发错误。有人可以帮我吗?
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)