0

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

问题:-如果任何警报显示在任何视图中并且我们正在使应用程序成为背景 - 前景,则应用程序会从该屏幕进入第三个选项卡,并且警报仍然存在,如果我们单击警报按钮,那么按照IOS的规则警报屏幕的“自我”对象被释放(因为现在我们在主屏幕中并且警报在这里)并且应用程序崩溃!

尝试了一些解决方案:-

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

[_alertToRemoveContactdismissWithClickedButtonIndex:1 动画:NO];

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

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

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

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

*ContactShowViewController 将与屏幕不同的地方提前谢谢!

4

2 回答 2

1

让我们试试单例:

__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];
}
}
于 2014-05-08T07:33:43.213 回答
0

我在以下解决方案的帮助下解决了这个问题:-

1.我创建了一个 UIAlertView 的应用程序委托实例。

2.我实现了一个警报视图委托方法“将呈现警报视图......”,该方法将所有警报视图对象作为参数提供给我,我已将其分配给我的警报视图的应用程序委托对象。

3.在应用程序生命周期方法“applicationDidEnterBackground”上,我使用下面的代码......,它退出了我从后台到前台的警报dailog......

if ([AppDelegate shared].alertObserver) {

  //Dismissing alert which was shown before moving to background

    [[AppDelegate shared].alertObserver dismissWithClickedButtonIndex:0 animated:NO];
    [AppDelegate shared].alertObserver=nil;
}
于 2014-05-26T05:12:54.027 回答