1

I think i found a bug in IOS SDK but i'm not sure how to overcome this issue without heavily modifying my code.

The problem? If i present modal view controller, than the user moves the app to background state, When the user comes back to the app, i switch the rootViewController to a different view controller, where i validate the user session and make some more logic. After this step is finished, i replace my original rootViewController. The problem is that the modalViewController that was presented by the rootViewController, is hidden / not showing. when i try to dismiss it it gives me an error that i'm trying to dismiss a view that it isn't visible.

when i try to present it again (or just another view controller for example), it errors me that i try to present view controller when another view controller is presented.

So, i can't dismiss the modal view controller and i can't present a new one.

To summarize, it seems that if you present a modalviewcontroller, than change your rootViewController to another viewcontroller, and restore the original rootViewController -> Any modals that where presented is in kinda limbo state.

Anyone can figure this out? any solution other the "don't replace your rootviewcontroller"?

Thanks alot

4

2 回答 2

1

您为什么要寻找“不要替换您的 rootviewcontroller”以外的解决方案。这才是正确的引导。这不是 iOS 中的错误。一般来说,你不应该替换根视图控制器。

听起来您真正想要的是第三个视图控制器,用作窗口的根视图控制器,并将主视图控制器和入口视图控制器作为子视图控制器进行管理。尝试一下并重新使用视图控制器,如果您遇到问题,我们可以尝试提供帮助。

视图控制器旨在以非常特定的方式工作,如果您滥用它们,您将体验到各种不良影响。有时你一开始会侥幸逃脱,但请放心,最后它会回来咬你。

查看控制器编程指南

于 2013-05-25T15:13:24.287 回答
1

假设您想保留原始方法,即在两个控制器之间进行交换,而不是使用第三个来管理它们,您可以在从后台返回时关闭呈现的视图控制器,然后再换出根视图控制器。

例如,在您的应用程序委托的 -applicationWillEnterForeground: 中:

if (self.window.rootViewController.presentedViewController != nil) {
        // do any tear-down relating to the modally presented view controller
        // Now dismiss it.
        [self.window.rootViewController dismissViewControllerAnimated:NO
                                                           completion:nil];
    }

这将消除导致无法显示新视图控制器的错误消息的情况,因为一个新视图控制器已经出现。

于 2013-07-21T16:11:13.083 回答