调用dismissViewControllerAnimated后,不会从堆栈中删除iOS 8视图

时间:2015-06-16 15:15:13

标签: ios objective-c iphone

这是我关于SO的第一篇文章,但我对该网站非常熟悉。我目前有一个正常工作的应用程序,直到最近的iOS更新。情况如下:

我有一个带有一个包含TableViewController的页面的PageViewController。当手机方向从纵向更改为横向时,将创建模态视图并使用模态segue呈现给用户。如果用户然后将手机的方向更改为肖像,则应用程序崩溃。

我花了很长时间尝试做工作并找到/创建解决方案,但没有运气。我发现正在调用“dismissViewControllerAnimated”并且正在取消分配模态视图。但是,我在“orientationChanged”函数的开头有一个print语句。它在第一次从横向到纵向打印一次。但是,如果用户再次将手机旋转到横向并返回到纵向,则“orientationChanged”现在将被调用两次,就好像视图控制器从未从堆栈中移除一样。如果用户继续执行此操作10次,例如,在第10次“orientationChanged”将连续调用10次。

这对我没有任何意义。如果正在取消分配模态视图,那么这怎么可能呢?是否有存储在某处的模态视图的副本?我试图将模态segue改为push segue,但没有运气。它会导致同样的事情。使用随附的push segue和导航栏,我能够向后浏览视图堆栈。堆栈有我所需的模态视图的重复副本,就像它们从未从堆栈中删除一样,并且堆栈的底部是我的TableViewController。

这是我的orientationChanged函数:

- (void)orientationChanged:(NSNotification *)notification
{
    NSLog(popModalView ? @"Yes" : @"No");
    NSLog(@"Index:%lu",(unsigned long)self.pageIndex);
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && popModalView == NO)
    {
        [self performSegueWithIdentifier:@"DisplayGraphNumberOfJobs" sender:self];
        popModalView = YES;
    }
    else if (UIDeviceOrientationIsPortrait(deviceOrientation) && popModalView == YES)
    {
        NSLog(@"dismiss");
        [self dismissViewControllerAnimated:YES completion:nil];
        popModalView = NO;
    }
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"DisplayGraphNumberOfJobs"])
    {
        GraphJobTotalsVC *graphJobs = [segue destinationViewController];
        //initialize graphJobs...
    }
}

作为旁注,我的PageViewController有3个页面,每个页面都有与此问题相同的问题。所以解决一个页面应该解决所有问题,希望如此。我查看了苹果的所有文档,但没有运气。我也看过无数其他的SO答案。我希望有一个人可以帮助我。提前谢谢你。

0 个答案:

没有答案