Iphone 如果有其他改变
请帮忙。每次我触摸UIButton时,我的标签应该增加现有的数字(1,2,3,4…),如果我的UIImageView.image=image1.png,并且我当时按下UIButton,我的标签应该减少-10。减少和增加工作量,但如果我从34减少到24,下一次按下增加按钮时,它将从34增加,而不是从现有的24增加 这是我的密码:Iphone 如果有其他改变,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,请帮忙。每次我触摸UIButton时,我的标签应该增加现有的数字(1,2,3,4…),如果我的UIImageView.image=image1.png,并且我当时按下UIButton,我的标签应该减少-10。减少和增加工作量,但如果我从34减少到24,下一次按下增加按钮时,它将从34增加,而不是从现有的24增加 这是我的密码: if (UIImageView.image == [UIImage imageNamed:@"image1.png"]) { NSString *data
if (UIImageView.image == [UIImage imageNamed:@"image1.png"]) {
NSString *dataMinus = [NSString stringWithFormat:@"%i",scoreIncrease - 10];
[self.label setText:dataMinus];
}
else {
NSString *dataToSend = [NSString stringWithFormat:@"%i",scoreIncrease++];
[self.label setText:dataToSend];
}
请帮助解决此问题。请执行以下操作:
if (UIImageView.image == [UIImage imageNamed:@"image1.png"]) {
scoreIncrease = scoreIncrease - 10; // Store the new value
NSString *dataMinus = [NSString stringWithFormat:@"%i", scoreIncrease];
[self.label setText:dataMinus];
}
else {
NSString *dataToSend = [NSString stringWithFormat:@"%i",scoreIncrease++];
[self.label setText:dataToSend];
}
在其他情况下,
scoreIncrease++
导致scoreIncrease=scoreIncrease+1
,因此新值存储在scoreIncrease
变量中,您不需要在if
语句中使用的额外语句来将新值存储在scoreIncrease
中++
操作符将使其打印出来然后,按照预期,分数将变量增加1。然而,在第一种情况下,你根本没有改变变量的值——你只是告诉它打印出任何值,减去10。您需要另一行实际减去10来修改变量
if (UIImageView.image == [UIImage imageNamed:@"image1.png"]) {
scoreIncrease=scoreIncrease-10;
NSString *dataMinus = [NSString stringWithFormat:@"%i",scoreIncrease];
[self.label setText:dataMinus];
}
else {
NSString *dataToSend = [NSString stringWithFormat:@"%i",scoreIncrease++];
[self.label setText:dataToSend];
}
试试这个可能会对你有所帮助。请把你的问题标题放在与你的问题相关的位置,看你的问题是“如果其他情况下图像会改变”,但在细节上,你不想改变你的图像,你只需改变分数