目前我在 viewDidLoad
上显示一个 UIAlertView
,但是一旦它进入后台并重新启动,它就不会再次出现。我该如何解决这个问题?我需要哪些代表,我该怎么做?
- (void)viewDidLoad {
[super viewDidLoad];
UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"Alert!" message:@"This is an Alert!" delegate:nil cancelButtonTitle:@"Cancel!" otherButtonTitles:nil, nil];
[myAlert show];
}
最佳答案
苹果文档:UIApplicationDidBecomeActiveNotification
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourMethod) name:UIApplicationDidBecomeActiveNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// don't forget remove it
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
}
- (void)yourMethod
{
UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"Alert!" message:@"This is an Alert!" delegate:nil cancelButtonTitle:@"Cancel!" otherButtonTitles:nil, nil];
[myAlert show];
}
关于ios - 当应用程序从后台带到前台时如何制作 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31153976/