2011-01-28 67 views
0

我使用下面的代碼來顯示一個對話框:iPhone SDK:如何隱藏警示框?

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"My Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[alert show]; 
[alert release]; 

你能告訴我如何再次隱藏警告框手機的變化方向是什麼時候?

+0

請參閱[降價編輯幫助](HTTP://計算器.com/editing-help)頁面以幫助格式化您的問題。最重要的是,你應該在你的代碼之前放置四個空格,所以它被格式化爲代碼(或者你可以選擇它並按下`{}`按鈕)。 – 2011-01-28 11:34:18

回答

3

首先,您必須在界面中保存對警報的引用。

@interface MyViewController : UIViewController { 
    UIAlertView *alert; 
} 
@property (nonatomic, retain) IBOutlet UIAlertView *alert; 

當您創建警報使用

self.alert = [[[UIAlertView alloc] initWithTitle:@"Info" message:@"My Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; 
[alert show]; 

,然後你必須添加另一種方法didRotateFromInterfaceOrientation:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
    [alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES]; 
    self.alert = nil; 
}