2012-08-09 8 views
7

UIAlertViewをプログラムでキャンセルするにはどうすればよいですか? 。これは、私はこのようなdismissWithClickedButtonIndex:を使用するUIAlertViewUIAlertViewをプログラムでキャンセルする

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]; 

答えて

11

てみ表示するために使用したコードである:ここでは

することに使用するコードです:

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

私はそれを入力していたときよりも20秒速いです。["cancelButtonIndex'"](https://developer.apple.com/library/ios/documentation/UIKit/Reference/ UIAlertView_Class/UIAlertView/UIAlertView.html#// apple_ref/occ/instp/UIAlertView/cancelButtonIndex)は常に "-1'"になるとは限りません。 –

4

あなたは

経由でそれを行うことができます
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated 

「キャンセル」ボタンのインデックスを呼び出している間。

スーパービュー([removeFromSuperview])からアラートビューを削除することもできます。 ARCを使用していない場合に備えて、「release」のalloc'dビューを確認してください。

関連する問題