0
내 showAlert 메서드에서 수많은 오류가 발생하여 나에게 이해가 가지 않습니다. 내 제목 로컬 변수를 만들었지 만 아직 선언되지 않은 식별자 오류 메시지가 표시됩니다. 코드 뒤에 나오는 오류 메시지를 주석 처리했습니다.showAlert 메서드에서 선언되지 않은 식별자
도와 주시겠습니까? 당신이 메시지 선언 이후 너무 많은 일 중괄호가
- (IBAction)showAlert
{
int difference = abs(targetValue - currentValue);
int points = 100 - difference;
score += points;
NSString *title;
if (difference == 0) {
title = @"Perfect!";
points += 100;
} else if (difference < 5) {
if (difference == 1) {
points += 50;
}
title = @"You almost had it!";
} else if (difference < 10) {
title = @"Pretty good!";
} else {
title = @"Not even close...";
}
NSString *message = [NSString stringWithFormat:@"You scored %d points", points]; // unused variable 'message'
}
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:title // use of undeclared identifier 'title'
message:message
delegate:self
cancelButtonTitle:@"OK" // Expected ';' after top level declarator 2
otherButtonTitles: nil];
[alertView show]; // Missing '[' at start of message send expression
} // Expected external declaration
'제목'은 ivar입니까? –
'}'NSString 메시지 다음에? – onnoweb
예, '}'NSString 메시지 다음에 모든 문제가 발생했습니다. '제목'은 지역 변수이며 ivar은 아닙니다. – pdenlinger