2011-11-28 2 views
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 
+0

'제목'은 ivar입니까? –

+0

'}'NSString 메시지 다음에? – onnoweb

+0

예, '}'NSString 메시지 다음에 모든 문제가 발생했습니다. '제목'은 지역 변수이며 ivar은 아닙니다. – pdenlinger

답변

1

: 여기

는 BullseyeViewController.m 파일의 코드입니다. 그냥 제거하십시오. 변수 제목이 범위를 벗어나는 이유는 무엇입니까?

- (IBAction)showAlert 
{ 
    ... 

    NSString *message = [NSString stringWithFormat:@"You scored %d points", points]; // unused variable 'message' 
    // REMOVE THIS => } 


    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 
관련 문제