我有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/