Objective c 为什么我会得到';表达式结果未使用';警告
我有一段代码给了我一个“表达式结果未使用”的警告。我不知道我做错了什么。请帮忙Objective c 为什么我会得到';表达式结果未使用';警告,objective-c,ios,expression,Objective C,Ios,Expression,我有一段代码给了我一个“表达式结果未使用”的警告。我不知道我做错了什么。请帮忙 if(task.typeForThis.typeID == @"DivisionAT"){ probsPerDayLabel.hidden = NO; whatToDoLabel.hidden = YES; //int ppdi = task.probsPerDay; //NSString *ppd = [NSString stringWithFormat: @"%i", ppd
if(task.typeForThis.typeID == @"DivisionAT"){
probsPerDayLabel.hidden = NO;
whatToDoLabel.hidden = YES;
//int ppdi = task.probsPerDay;
//NSString *ppd = [NSString stringWithFormat: @"%i", ppdi];
probsPerDayLabel.text = @"Do %i problems today.",task.probsPerDay; //Right here
}
您需要使用
NSString
的stringWithFormat:
方法,如下所示:
probsPerDayLabel.text = [NSString stringWithFormat:@"Do %i problems today.", task.probsPerDay];
这一行:
probsPerDayLabel.text = @"Do %i problems today.",task.probsPerDay
应该是:
probsPerDayLabel.text = [NSString stringWithFormat:@"Do %i problems today.",task.probsPerDay];
在您的版本中,task.probsPerDay的结果完全未使用,标签上的文本将是“Do%i problems today.”,而
%i
不会被数字替换。@Joe:这不可能是真的。您将得到一个整数转换为指针错误。我在Xcode中尝试过,但没有。@Joe:不,它相当于(probsperdaylab.text=@“今天解决%I问题”)、task.probsPerDay代码>。逗号的优先级低于赋值。