
58
|
第
2
章
图
2
-
12
:为文本框创建一个 Outlet
再次显示了一个对话框让你输入一个
Action
名称,如图
2-13
所示。输入
buttonPressed
,然后点击
Connect
按钮。这将在
MainMenuViewController
类
中添加一个新的方法。
图
2
-
13
:创建一个 Action
14.
在新方法
buttonPressed
中加入代码。
我们使用的代码如下:
let alert = UIAlertController(title: "Button tapped",
message: "The button was tapped",
preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK",
style: UIAlertAction.Style.default,
handler: nil))
self.present(alert,
animated: true, completion: nil)