解除自定义警报视图并解除segue问题?

时间:2014-12-09 09:47:59

标签: ios objective-c segue

我有一个非常具体的问题,我无法管理。我有一个使用Storyboardcustom segues的应用程序。

我有一个视图控制器,我必须在其中显示自定义警报视图以确认或拒绝按下按钮时的操作。自定义提醒构建为带有标题文本的视图和2个用于确认取消的按钮。

在初始初始化时,我为该自定义警报视图添加观察者:

    [[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(customAlertViewNotoficationHandler:)
                                                 name: constDismissCustomAlertViewNotificationLabel object:nil];

按下按钮,我创建视图并使用以下方式显示:

[self presentViewController:vc animated:YES completion:nil];

当我按取消时,我只是关闭视图。该方法在自定义类中实现:

-(void) doDismissAlert:(NSString*) isConfirm {

    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

    //raise notification about dismiss
    [[NSNotificationCenter defaultCenter]
     postNotificationName:constDismissCustomAlertViewNotificationLabel
     object:isConfirm];

}

isConfirm会显示我是按确认还是取消按钮。

如果我确认操作,我必须调用SOAP服务。它从一个单独的线程开始并返回确认结果(对于SOAP服务,我使用sudzc.com)。如果没有错误,我将使用自定义segue继续使用另一个视图控制器:[self performSegueWithIdentifier: @"segRec2RecDet" sender: self];

Segue表演:

- (void)perform {
    [[self sourceViewController] presentViewController:[self destinationViewController] animated:YES completion:nil];
}

如果我会话已过期错误,我必须转到登录视图控制器。对于此操作,我使用[self performSegueWithIdentifier:@"unwSegReturnToLogin" sender:self];转到登录。这是我的问题出现的地方。我收到错误:

2014-12-09 11:43:27.558 PA-PAY[10605:613] attempt to dismiss modal view controller
whose view does not currently appear. self = <PESvcRecharge: 0x7f9920e7d030>
modalViewController = <PESavCustomAlertView: 0x7f9920f82990>
2014-12-09 11:43:27.558 PA-PAY[10605:613] attempt to dismiss modal view controller
whose view does not currently appear. self = <PESvcLogin: 0x7f9920d37f00>
modalViewController = <PESvcRecharge: 0x7f9920e7d030>

显然有人试图解雇PESavCustomAlertView,它已经处于解雇状态,而且无法进入PESvcLogin。

很奇怪,在我使用iOS 8.1的模拟器中,上面的代码可以工作。它在7.1

中崩溃

有任何建议如何处理?

修改

我的视图层次结构看起来像(仅适用于逻辑的这一部分):

登录VC - &gt; 菜单VC - &gt; 充值VC - &gt; (自定义提醒) - &gt; Ticket VC

仅需要

自定义提醒,因为我的规范要求它必须如此。我也可以有正常的警报视图来显示有错误。如果错误会话已过期,我必须返回登录VC

备注:自定义提醒不属于故事板。它是与我的自定义类连接的xib文件。

1 个答案:

答案 0 :(得分:1)

关闭动画可能会解决问题,但我怀疑视图堆栈管理代码存在更深层次的问题。应解除模态视图控制器关闭后应运行的代码应添加到

的完成块中

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

允许您保留动画行为

    [self.presentingViewController dismissViewControllerAnimated:YES completion:^{

        // Post notfication here

    }];