objective-c - 比较UILabel得分

标签 objective-c ios xcode

我有2个UILable:

myScore.text;和hisScore.text;

当我的NSTimer达到0时,我有以下代码:

if (MainInt <= 0) {
        [Mytimer invalidate];

        if (myScore.text < hisScore.text) {
            UIAlertView *win = [[UIAlertView alloc]initWithTitle:@"Congrats" message:@"You WIN" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [win show];
        }
        else if(myScore.text > hisScore.text) {
            UIAlertView *lose = [[UIAlertView alloc]initWithTitle:@"Hmmmm" message:@"You lose :(" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [lose show];
        }

        else if(myScore.text == hisScore.text) {
            UIAlertView *tie = [[UIAlertView alloc]initWithTitle:@"Not Bad" message:@"No winners. TIE" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [tie show];
        }
    }

如果我的分数大于他的分数,我该如何比较?我的代码不起作用。请帮助。

最佳答案

您当前正在比较两个字符串。

您将不得不比较那些字符串的整数值。
要在Objective-C中访问字符串的整数值,可以使用intValue方法,如下所示:

[myScore.text intValue]

关于objective-c - 比较UILabel得分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13354412/

相关文章:

objective-c - 释放以正确方式返回的对象?

ios - AdMob Interstitial 每五场比赛一次

ios - 词法或预处理器问题 - 找不到 Cordova/CDVAppDelegate.h

ios - NSMutableURLRequest "The request timed out"问题。 .

iOS 应用程序 - 无法在 bundle 中加载 NIB

ios - 将值返回给 tableView 函数

ios - 许多不同字符串之间的 Swift UIView.animate

ios - 在 Swift 上设置定时器

ios - 如何在将 UIImage 保存到磁盘之前唯一标识它?

ios - 如何以编程方式获取正确的 iOS 版本?