gpt4 book ai didi

ios - 当应用程序从后台带到前台时如何制作 UIAlertView

转载 作者:行者123 更新时间:2023-11-28 21:43:35 25 4
gpt4 key购买 nike

目前我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com