我有一个IBAction UILabel,每次按下时都会添加一个数字。我有一个Total UITextField,它添加了所有3个UILabel。在我点击减法(buttonTap2)UILabel按钮之前,获得总数似乎没问题。 以下是IBAction UILabel代码不起作用的示例:
- (IBAction)buttonTap2:(id)sender {
int value = [currentLabel.text intValue] - 1;
currentLabel.text = [NSString stringWithFormat:@"%d",value];
int n1 = [label2.text intValue]; // total labels
int n2 = [label3.text intValue];
int n3 = [label4.text intValue];
int s = n1 - n2 - n3;
NSString *sn = [NSString stringWithFormat:@"%d",s];
[tex7 setText:sn];
答案 0 :(得分:1)
你有什么问题?什么是“tex7”?如果它应该是文本字段或标签,它是否在Interface Builder中正确链接?您可能错过了它,因为它不是很具描述性。
答案 1 :(得分:0)
在这种情况下,如果n1n2> n3,则只会得到负值。如果要将负数转换为正数,则采用数字模式,将数字转换为正数。你要做的另一件事是,如果结果数小于0,那么主持结果数,然后将结果数加到-1,