UITabbarController关闭模式UINavigationController [英] UITabbarController dismiss modal UINavigationController
问题描述
我在这里遇到了一个非常有趣的问题.我的iPhone应用程序在AppDelegate中有一个UITabbarController作为rootViewController.
I got a very interesting problem here. My iPhone app has an UITabbarController as rootViewController in the AppDelegate.
如果该应用是首次打开,则必须对其进行基本配置.为此,我创建一个UINavigationController并告诉tabbarController以模态形式显示它:
If the app is opened the first time, it must be configured basically. For this purpose I create an UINavigationController and tell the tabbarController to present it modally:
firstRun = [[firstRunViewController alloc] init];
navCtrl = [[UINavigationController alloc] initWithRootViewController:firstRun];
[[self tabBarController] presentModalViewController:navCtrl animated:NO];
配置完成后,我想摆脱firstRunViewController.我经常使用-dismissModalViewControllerAnimated:
.
When the configuration is done, I'd like to get rid of the firstRunViewController. I'm using this technique very often, using -dismissModalViewControllerAnimated:
.
但是在这个星座中这是行不通的.我叫什么解雇的控制器无关紧要. 我通过了原因自身和其他几个控制器的tabbarController,rootViewController,当前活动的viewController进行了尝试.
But in this constellation this doesn't work. It doesn't matter from what controller I'm calling the dismiss. I tried it via the tabbarController, the rootViewController, the currently active viewController, of cause self and several other controllers.
每当我打电话给-dismissModalViewControllerAnimated:
时,都会出现此异常:
EVERY TIME I call -dismissModalViewControllerAnimated:
I get this exception:
'UIViewControllerHierarchyInconsistency', reason: 'presentedViewController for controller is itself on dismiss for: <UINavigationController:…
有人可以帮忙吗?在此先感谢朱利安
Can anybody help? Thanks in advance, with kind regards, Julian
编辑 在我的AppDelegate中,我将UITabbarController用作主窗口的rootViewController:
EDIT In my AppDelegate I'm using a UITabbarController as rootViewController for the main window:
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
然后我要创建一个UINavigationController并告诉UITabbarController呈现modalViewController:
Then I'm creating an UINavigationController and tell the UITabbarController to present the modalViewController:
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:firstRun];
[[self tabBarController] presentModalViewController:navCtrl animated:NO];
当我现在在第一个ViewController上调用-dismissModalViewControllerAnimated:时,我从上面得到了错误.
When I now call -dismissModalViewControllerAnimated: on the firstViewController I'm getting the error from above.
推荐答案
我终于找到了答案! 我只是看不到树木的木头!我现在很开心! :)
I finally found the answer myself! I just couldn't see the wood for the trees! I'm quite happy right now! :)
我确实做了一些愚蠢的事情:在设置viewControllers的最后一个viewController中,我不得不根据用户是否为管理员来更改tabars viewControllers.所以我做到了:
I did really silly things: In the last viewController of the setup viewControllers I had to change the tabars viewControllers corresponding to whether the user is administrator or not. So I did:
appDelegate.tabBarController.viewControllers = [NSArray arrayWithObjects:appDelegate.readState,
appDelegate.navCtrl,
appDelegate.settings, nil];
您可以看到我正在将AppDelegate的"navCtrl"添加到选项卡的viewControllers中.因此,我试图关闭刚刚添加到parentViewControllers(UITabbarController)子控制器中的viewController.
You can see that I was adding the AppDelegate's "navCtrl" to the tabbar's viewControllers. So I was trying to dismiss a viewController I just added to the parentViewControllers (UITabbarController) sub-controllers.
不建议同时删除我想呈现的内容! :))
Dismissing something I want to present just in the same moment is NOT advisable! :))
这篇关于UITabbarController关闭模式UINavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!