2012-08-09 14 views
7

Programowo programowo anulować program UIAlertView? Jest to kod, który używam, aby pokazać UIAlertViewAnuluj program UIAlertView programowo

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Save Background" message:@"Downloading..." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil]; 
    CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 70.0); 
    [myAlertView setTransform:myTransform]; 
    [myAlertView show]; 

Odpowiedz

11

spróbuje użyć dismissWithClickedButtonIndex: tak:

Oto kod używać:

[myAlertView dismissWithClickedButtonIndex:-1 animated:YES]; 
+0

+1 do Ciebie za bycie o 20 sekund szybciej niż podczas pisania ... ["cancelButtonIndex"] (https://developer.apple.com/library/ios/documentation/UIKit/Reference/ UIAlertView_Class/UIAlertView/UIAlertView.html # // apple_ref/occ/instp/UIAlertView/cancelButtonIndex) nie zawsze będzie "-1". –

4

Można to zrobić poprzez

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated 

podczas wywoływania indeksu przycisku "Anuluj".

Można również po prostu usunąć widok alertu z podglądu (np. "removeFromSuperview"). Upewnij się, że "release" jest widokiem alokacji na wypadek, gdy nie używasz ARC.

Powiązane problemy