首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPhone SDK:如何隐藏警告框?

iPhone SDK:如何隐藏警告框?
EN

Stack Overflow用户
提问于 2011-01-28 19:30:07
回答 1查看 1.1K关注 0票数 0

我使用以下代码来显示一个警告框:

代码语言:javascript
复制
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"My Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];  
[alert show];  
[alert release];

你能告诉我当手机改变方向时如何再次隐藏提示框吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-28 20:02:36

首先,您必须在您的界面中保存对警报的引用。

代码语言:javascript
复制
@interface MyViewController : UIViewController {
    UIAlertView *alert;
}
@property (nonatomic, retain) IBOutlet UIAlertView *alert;

创建警报时,您将使用

代码语言:javascript
复制
self.alert = [[[UIAlertView alloc] initWithTitle:@"Info" message:@"My Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];  
[alert show]; 

然后,您必须添加另一个方法didRotateFromInterfaceOrientation:

代码语言:javascript
复制
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES];
    self.alert = nil;
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4827710

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档