iOS Swift 按钮文本不会在单击时更改

标签 ios swift

    import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var buttonText: UIButton!


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.


    }
    @IBAction func btnButtonACTION(sender: UIButton) {
        buttonText.setTitle("changetext", forState: .Normal)

    }
}

我正在尝试通过 Xcode 学习 Swift 语言的基础知识。我的想法是在单击按钮时更改按钮文本。但它不会改变。有什么我错过的吗?

最佳答案

您正在使用:

buttonText.setTitle("changetext", forState: .Normal)

试试这个:

buttonText.setTitle("changetext", forState: UIControlState.Normal)

关于iOS Swift 按钮文本不会在单击时更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32288585/

相关文章:

ios - swift API 请求和 JSON 解析

ios - 原生app与html5共享sqlite数据库

ios - 如何在 Swift 中显示动态高度的 3*3 CollectionView 单元格

ios - 跨应用程序使用产品标识符

ios - 如何为多个 View Controller 使用 SWRevealviewcontroller 库

ios - Swift iOS - 如何将 UIPopoverBackgroundView 类中的方法连接到不同类中的 PopoverController?

ios - Swift 中数组的直方图

swift - 如何自动布局 ScrollView 以适应其中的内容 View ?

ios - 快速在选项卡式 View 之间传递数据

ios - 仅在代码中添加按钮?