gpt4 book ai didi

ios - 将所有 UIAlertView 对象作为全局对象访问以对其进行通用控制(在解除分配 View Controller 后解决警报中的 CRASH)

转载 作者:行者123 更新时间:2023-11-29 02:58:55 24 4
gpt4 key购买 nike

我的要求是将我的应用程序的第三个选项卡作为主屏幕,并且每当用户在后台移动应用程序并再次将应用程序移动到前台时,它应该是主屏幕作为我们的第三个选项卡而不是应用程序在应用程序中的任何位置。 此问题已得到处理(将第三个选项卡设为主屏幕,而不是应用程序位于应用程序中的任何位置/场景中)。但我现在遇到了此解决方案产生的问题。

问题:- 如果在任何 View 中显示任何警报并且我们正在将应用程序设为背景-前景,应用程序会从该屏幕转到第三个选项卡,并且警报仍然存在,如果我们点击警报按钮,然后根据 IOS 的规则,警报屏幕的“ self ”对象被释放(因为现在我们在主屏幕并且警报在这里)和应用程序崩溃!

尝试了一些解决方案:-

1.在屏幕中,我制作了一个 UIAlertView 的全局对象,并在屏幕的 applicationDidBecomeActive 方法中使用以下代码行...

[_alertToRemoveContact dismissWithClickedButtonIndex:1 animated:NO];

这是该 View 的工作代码,但我的解决方案问题是我需要在应用程序的所有位置创建警报 View 的全局对象,这是一项非常耗时的任务,因为我我在项目中使用了大约 250 个警报。

2.每当应用程序移至后台时,我都会终止该应用程序在此解决方案中,问题是我的应用程序无法在后台运行其下载功能,因为该应用程序是被杀死。

需要帮助解决这个问题,如果有人需要更多解释,请发表评论。

我的崩溃日志....* -[ContactShowViewController respondsToSelector:]: 消息发送到释放实例 0x1138c4e0*

*ContactShowViewController 与屏幕的 a/c 不同提前致谢!!!

最佳答案

让我们尝试一下单例:

__strong static AlertUtil* _sharedInstance = nil;
@implementation AlertUtil
{
UIAlertView *alertView;
}
+ (AlertUtil *)sharedInstance
{
@synchronized(self)
{
if (nil == _sharedInstance)
{
_sharedInstance = [[AlertUtil alloc] init];
}
}
return _sharedInstance;
}
- (void)showConfirmAlertWithMessage:(NSString *)msg cancelBtnTitle:(NSString *)btn1 okbtnTitle:(NSString *)btn2 delegate:(id)delegate tag:(int)tag
{
alertView = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:delegate cancelButtonTitle:btn1 otherButtonTitles:btn2, nil];
alertView.tag = tag;
[alertView show];
}
- (void)cancel
{
if (alertView){
[alertView dismissWithClickedButtonIndex:0 animated:NO];
}
}

关于ios - 将所有 UIAlertView 对象作为全局对象访问以对其进行通用控制(在解除分配 View Controller 后解决警报中的 CRASH),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23521832/

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