检查Swift中的UIButton标题

use*_*983 9 uibutton ios swift xcode6

我有一个按钮,按钮的标题是一个整数.

correctAnswer = randomNumber1 + randomNumber2
button1.setTitle("\(correctAnswer)", forState: UIControlState.Normal)
Run Code Online (Sandbox Code Playgroud)

我试图检查按钮的标题,所以将其转换为整数并在if语句中使用它,但无法使其工作.

button1.titleLabel?.text?.toInt()
    if button1.titleLabel == correctAnswer { //most probably I am making a mistake here.
        scoring() } else {
        println(button1.titleLabel?.text!)
Run Code Online (Sandbox Code Playgroud)

我是新手,我甚至可能对我的方法有疑问,你的帮助将不胜感激.

Chi*_*buZ 23

你应该使用 button1.currentTitle