2014-11-12 1 views
5

정지 : 내가 UIAlertViewUIAlertView 위임에 두 버튼을 동시에 눌러 경우가 호출되지 않습니다, 전체 화면 정지 (아무것도 경고보기를 해제 할 경우에도, tappable 없다).내가이 버그가 응용 프로그램

이전에이 버그를 본 사람이 있습니까? 단 하나의 버튼으로 도청 UIAlertView을 제한하는 방법이 있습니까?

- (IBAction)logoutAction:(id)sender { 
     self.logoutAlertView = [[UIAlertView alloc] initWithTitle:@"Logout" 
                   message:@"Are you sure you want to logout?" 
                  delegate:self 
                cancelButtonTitle:@"No" 
                otherButtonTitles:@"Yes", nil]; 
     [self.logoutAlertView show]; 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if ([alertView isEqual:self.logoutAlertView]) { 
     if (buttonIndex == 0) { 
      NSLog(@"cancelled logout"); 
     } else { 
      NSLog(@"user will logout"); 
      [self performLogout]; 
     } 
     self.logoutAlertView.delegate = nil; 
    } 
} 
+0

버전은 무엇? – trojanfoe

+0

iOS 8.1은 최신 XCode – user1028028

+0

을 사용하는 완전한 버전입니다. 그리고 alertview 대리인이 올바르게 보존 되었습니까? – trojanfoe

답변

2

예, UIAlertView에서 여러 개의 버튼을 탭 할 수 있으며 각 탭마다 대리자 메소드가 호출됩니다. 그러나이 앱이 '정지'해서는 안됩니다. 코드를 단계별로 실행하여 문제를 찾으십시오.

이 처리되는 여러 이벤트를 방지 첫 번째를 처리 한 후 전무로 UIAlertView의 위임 속성을 설정하려면 :

- (void)showAlert { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; 
    [alert show]; 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    // Avoid further delegate calls 
    alertView.delegate = nil; 

    // Do something 
    if (buttonIndex == alertView.cancelButtonIndex) { 
    // User cancelled, do something 
    } else { 
    // User tapped OK, do something 
    } 
} 
+1

이것이 작동하지 않는 것 같습니다. – user1028028

+0

게시하기 전에 테스트를했기 때문에 더 구체적 일 수 있습니다. –

+0

질문에 추가 된 코드를 참조하십시오 .. – user1028028

1

사용 UIAlertController를 아이폰 OS 8 : 아이폰 OS의

if ([UIAlertController class]) 
{ 
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Logout" message:@"Are you sure you want to logout?" preferredStyle:UIAlertControllerStyleAlert]; 
    [alert addAction:[UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) 
    { 
     NSLog(@"cancelled logout"); 
    }]]; 
    [alert addAction:[UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) 
    { 
     NSLog(@"user will logout"); 
     [self performLogout]; 
    }]]; 

    [self presentViewController:alert animated:YES completion:nil]; 
} 
else 
{ 
    self.logoutAlertView = [[UIAlertView alloc] initWithTitle:@"Logout" 
                 message:@"Are you sure you want to logout?" 
                delegate:self 
              cancelButtonTitle:@"No" 
              otherButtonTitles:@"Yes", nil]; 
    [self.logoutAlertView show]; 
} 
+0

Will not work ... 컨트롤러에 경고를 표시합니다. 그 시점에서 컨트롤러가 화면 가운데에 위치하지 않습니다 (슬라이드가 활성화 된 상태에서 햄버거 메뉴가 활성화 됨). 그러면 경고가 표시됩니다. way off center 또는 경고가 최상위 컨트롤러 뒤에 숨겨져 있기 때문에 표시되지 않는 메뉴가있는 백그라운드 컨트롤러를 사용하는 경우 – user1028028

+0

@ user1028028 그러면 백그라운드 컨트롤러가 아닌 루트 컨트롤러를 구해야합니다. was rootViewCotroller = [[[UIApplication sharedApplication] .windows lastObject] rootViewController] – ChikabuZ

+0

다른보기 컨트롤러 뒤에 표시되는 경고 인 AlertView와는 달리 중심에 위치 할 것입니다. – user1028028