2012-04-28 56 views
1

我的委托上有两个选项卡控制器,我想根据需要切换它们。 RootController显示为默认,当我想从另一个类我用显示secondController,在两个控制器之间的iOS切换

myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [appDelegate.window addSubview:appDelegate.secondController.view]; 
    [appDelegate.rootController.view removeFromSuperview]; 

问题是,当我想回去用同样的方法。由于不好的acces异常崩溃...

myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [appDelegate.window addSubview:appDelegate.rootController.view]; 
    [appDelegate.secondController.view removeFromSuperview]; 

任何帮助,将不胜感激。谢谢。

+0

你在你的应用的两个tabbarcontrollars? ..或者只是一个tabbarcontroller有两个视图控制器在里面? – Shubhank 2012-04-28 18:39:19

+0

两个tabBarControllers! – Jaume 2012-04-28 18:39:58

+0

给你的BOOL appdidFinishLaunching方法代码..它应该在应用程序delegate.m文件 – Shubhank 2012-04-28 18:41:58

回答

2

您不应该从Superview中删除rootController。删除该行

[appDelegate.rootController.view removeFromSuperview]; 

,当你想回到你rootController只需添加下面几行:

myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate]; 
[appDelegate.secondController.view removeFromSuperview]; 
+0

谢谢,但同样的问题!我在我的委托上设置了一个空函数来测试它,问题似乎来自与superview无关的回调单例... – Jaume 2012-04-28 19:21:11

+0

好了,问题来自ARC。我设置标志来禁用它只在一些类中,所以appDelegate不需要保留。谢谢你的帮助 – Jaume 2012-04-30 15:16:39