2013-07-16 2 views
1

작업과 나는 같은 함수 안에있는 UIAlert하지 :목표 - C UIAlert 버튼 내가 목표 - C에서 초보자입니다

- (void)loadJSON 
{ 

    Reachability *networkReachability = [Reachability reachabilityForInternetConnection]; 
    NetworkStatus networkStatus = [networkReachability currentReachabilityStatus]; 
    if (networkStatus == NotReachable) { 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Announcement" message: @"No Connection" delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; 
     }); 
    } else { 
     //some code 
    } 
} 

사용자가 확인 버튼을 클릭 할 때이 기능을 발사한다을 loadJSON 기능을 불러 오시겠습니까? 사용자가 메시지를보고 알았지 경우 여전히 인터넷 연결, 디스플레이 경고를 클릭하지, 거기에, 인터넷에 연결하지 UIAlert를 표시하는 경우 여기

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
    [self loadJSON]; 
} 

내 최종 목표는 (이어야 난 그렇게 생각). 인터넷 연결이 끊어져 경고 메시지가 한 번 나타납니다.

내 코드에 문제가 있습니까?

답변

4

alertView에 대리자가 할당되지 않았습니다.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Announcement" 
                message: @"No Connection" 
                delegate: self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
+1

예이 문제가 발생했습니다. 그것이 "delegate : self"인지 확인하십시오. "delegate : nil"을 가지고 있었는데 아무 일도 없었습니다. 감사합니다 Gururaj.T Logged –