2014-11-12 14 views
5

Bu hatayı alıyorum: her iki düğmeyi aynı anda UIAlertView üzerinde tıklatırsam UIAlertView temsilci çağrılmayacak ve tüm ekran donuyor (uyarı görünmüyor olsa bile hiçbir şey devre dışı bırakılamaz).UIAlertView uygulamasında 2 düğmeyi aynı anda dokunma uygulaması

Bu hatayı daha önce gören oldu mu? UIAlertView'u tek bir tuşa dokunmanın bir yolu var mı?

- (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

Ne versiyonu? – trojanfoe

+0

iOs 8.1, en son XCode – user1028028

+0

kullanarak tam sürüm ve uyarı görüntüleme delegesinin düzgün bir şekilde korunuyor mu? – trojanfoe

cevap

2

Evet, bir UIAlertView öğesinde birden çok düğmeye basmak ve her bir musluk için çağrılan temsilci yöntemlerini kullanmak mümkündür. Ancak, bu, uygulamanızı "donduramaz". Sorunu bulmak için kodunuzu adım atın.

, işlenen birden fazla olayları önlemek ilkini işledikten sonra sıfıra UIAlertView en temsilci özelliğini ayarlamak için:

- (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

Bu işe yaramıyor gibi görünüyor – user1028028

+0

Belki de daha spesifik ol, çünkü bunu yayınlamadan önce test ettim. –

+0

soruya eklenmiş kodu görmek için .. – user1028028

1

Kullanım UIAlertController iOS 8: iOS

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

Çalışmayacaksınız ... kontrolör üzerinde bir uyarı görüntülüyor, bu noktada kontrol cihazım ekranda ortalanmıyor (hamburger menüsü etkin dışarı çıkar). merkezden çıkış yolu, ya da menüyü içeren arkaplan denetleyicisini kullanırsam, uyarı en üstteki denetleyicinin arkasına gizlendiğinden gösterilmez. – user1028028

+0

@ user1028028 Sonra benim kök denetleyicimi değil arka plan denetleyicisini almalıyım. rootViewCotroller = [[[[UIApplication sharedApplication] .windows lastObject] rootViewController] – ChikabuZ

+0

Çalışmıyor, ortalanmış olacak ancak diğer görünüm denetleyicilerinin arkasında görüntülenen bir uyarı olacak AlertView aksine – user1028028

İlgili konular