2012-08-28 4 views
1

인터넷이 연결되어 있지 않은 경우 경고보기를 사용하여 사용자에게 경고합니다. 경고보기에 두 개의 버튼이 있는데 둘 다 작동하지 않는 것 같습니다. 나는 .h 파일에 이미 구현했다. NSLog를 사용하여 클릭 할 때 응답하는지 확인했습니다. 콘솔에서 응답하지만 버튼을 눌렀을 때 아무 반응이 없습니다. 여기에 내 코드가있다.UIAlertView 단추가 작동하지 않습니다.

- (IBAction)startButton:(id)sender 
    { 
    if (![self connectedToNetwork]) 
    { 
     UIAlertView *internetAlert = [[UIAlertView alloc] initWithTitle: @"Network Error!" message: @"You are not connected to the internet" delegate: self cancelButtonTitle: @"OK" otherButtonTitles: @"Open Settings", nil]; 
     [internetAlert show]; 
    } 
    } 

- (void)alertView: (UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
    { 
    if (buttonIndex == 0) 
    { 
     NSLog(@"Ok clicked"); 
     HomeViewController *blah = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"]; 
     [self.view addSubview: blah.view]; 
    } 

    else if (buttonIndex == 1) 
    { 
     NSLog(@"Settings clicked"); 
     [[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"prefs:root=WIFI"]]; 
    } 
} 

내비게이션 컨트롤러가 없기 때문에 [self.contentView addSubview : blah.view]를 사용했습니다. 내가 잘못하고있는 것에 대한 생각은 무엇입니까

답변

0

여기 UIAlertView 버튼을 잘못 클릭했습니다. UIAlertView의 또 다른 메소드를 사용해야한다.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 

다음 코드로 변경하십시오.

- (IBAction)startButton:(id)sender 
{ 
    if (![self connectedToNetwork]) 
    { 
     UIAlertView *internetAlert = [[UIAlertView alloc] initWithTitle: @"Network Error!" message: @"You are not connected to the internet" delegate: self cancelButtonTitle: @"OK" otherButtonTitles: @"Open Settings", nil]; 
     [internetAlert show]; 
    } 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 0) 
    { 
     NSLog(@"Ok clicked"); 
     HomeViewController *blah = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"]; 
     [self.view addSubview: blah.view]; 
    } 

    else if (buttonIndex == 1) 
    { 
     NSLog(@"Settings clicked"); 
     [[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"prefs:root=WIFI"]]; 
    } 
} 

궁금한 점이 있으면 언제든지 문의 해주세요.

+0

나는 그것을 시도했다. 작동하지 않습니다. 내 NSLog는 버튼을 클릭하면 실제로 응답이 표시되지만 다른보기로는 변경할 수 없다는 것을 보여줍니다. – bumpfox

관련 문제