当我构建并分析我的应用程序时,我收到以下内存警告
"The left operand of '>' is a garbage value" at this line isTrue = (newLength > 20) ? NO : YES;
这里有什么问题。感谢您的帮助
(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSUInteger newLength;
BOOL isTrue;
if(textField == txtFirstName){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 20) ? NO : YES;
}
if(textField == txtLastName){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 20) ? NO : YES;
}
if(textField == txtEmail){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 100) ? NO : YES;
}
if(textField == txtCompanyName){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 30) ? NO : YES;
}
if(textField == txtPassword){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 30) ? NO : YES;
}
if(textField == txtRe_EnterPassword){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 30) ? NO : YES;
}
if(textField == txtZipCode){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 20) ? NO : YES;
}
if(textField == txtCountry){
newLength = [textField.text length] + [string length] - range.length;
//isTrue = (newLength > 30) ? NO : YES;
}
isTrue = (newLength > 20) ? NO : YES;
return isTrue;
}
最佳答案
当所有的 if 条件都失败时,问题就会出现,即。如果 textField
不是您期望的集合之一。
在这种情况下,newLength
永远不会被赋值,而是一个随机的垃圾值。
虽然这可能“永远不会发生”,但静态分析器并不知道这一点。
您应该将 newLength
初始化为默认值,可能为零。
关于iphone - '>' 的左操作数是垃圾值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7925436/