首先,您必須在界面中保存對警報的引用。
@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;
}
請參閱[降價編輯幫助](HTTP://計算器.com/editing-help)頁面以幫助格式化您的問題。最重要的是,你應該在你的代碼之前放置四個空格,所以它被格式化爲代碼(或者你可以選擇它並按下`{}`按鈕)。 – 2011-01-28 11:34:18