我試圖檢測一個NSNumber是否介於0和255之間。每當我運行應用程序,我都會收到警報視圖,即我的編號大於255,即使它不是。我沒有這個問題,0檢測是否NSNumber介於0和255之間
if (redValue < 0) {
NSLog(@"Red value is less than 0");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your number must be greater than 0." message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
} else if (redValue > 255) {
NSLog(@"Red value is greater than 255");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your number must be less than 255." message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
此外,我收到關於「否則,如果(redValue> 255)」行這樣的警告:尖和整數之間(有序的比較「的NSNumber *」和「INT '),所以我假設我必須將此NSNumber轉換爲整數?
看到這個問題的更多有關的NSNumber轉換成int:http://stackoverflow.com/questions/3555906/how-to-convert-nsnumber-to-int-in- objective-c –