我使用以下代码显示警告框:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"My Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
当手机改变方向时,您能告诉我如何再次隐藏提示框吗?
答案 0 :(得分: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;
}