ios – 检查Swift中的UIButton标题

前端之家收集整理的这篇文章主要介绍了ios – 检查Swift中的UIButton标题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个按钮,按钮的标题是一个整数.
correctAnswer = randomNumber1 + randomNumber2
button1.setTitle("\(correctAnswer)",forState: UIControlState.Normal)

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

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

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

解决方法

你应该使用button1.currentTitle
原文链接:https://www.f2er.com/iOS/335172.html

猜你在找的iOS相关文章