iOS模拟器中的按钮不起作用

时间:2017-07-13 15:42:41

标签: ios uiviewcontroller uibutton

我创建了一个简单的应用程序,我是iOS开发的初学者。 当我点击按钮时,它们无法正常工作。即使它们没有闪烁,因为点击时按钮通常会闪烁。

这是我写的代码:

import UIKit

class ViewController: UIViewController {
    @IBAction func showMessage() {
        let alertController = UIAlertController(title:"Hi!", message: "This is your first app", preferredStyle: UIAlertControllerStyle.alert)
        alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
        present(alertController, animated: true, completion: nil)
    }

    @IBAction func guitar() {
        let alertController = UIAlertController(title: "Hi!", message: "You have just clicked the guitar button!", preferredStyle: UIAlertControllerStyle.alert)
        alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
        present(alertController, animated: true, completion: nil)
    }

    @IBAction func car() {
        let alertController = UIAlertController(title: "Hi!", message: "You have just clicked the car button!", preferredStyle: UIAlertControllerStyle.alert)
        alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
        present(alertController, animated: true, completion: nil)
    }

    @IBAction func football() {
        let alertController = UIAlertController(title: "Hi!", message: "You have just clicked the football button!", preferredStyle: UIAlertControllerStyle.alert)
        alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
        present(alertController, animated: true, completion: nil)
    }
}

以下是应用UI的屏幕截图:

Screenshot of the simulator

我创建了四个按钮。创建按钮后,我在viewcontroller.swift文件中创建了四个函数。之后,我只是将这些功能链接起来,就像在屏幕截图中一样:

image

我正在关注Appcoda初学者iOS 10 Swift 3书。

0 个答案:

没有答案