0

我有一个 tabBarController,上面有三个 viewController。When viewController 1 is selected and I make a 90 degrees I hide the tabBar and I have to addsubview the current view to the tabBarController, otherwise a blank space appears where the tabBar was.

如果现在我将 iPhone 旋转到以前的方向(垂直正常位置)我 removeFromSuperview 视图,但视图控制器上没有显示视图,我想应该显示原始视图(addsubview 调用之前的那个),事实上如果我选择第二个 viewController,然后我回到 viewController 1,则视图会完美显示。

我不明白为什么会发生这种情况,你能帮帮我吗?

更新:

我认为问题是我在 tabbarcontroller 上添加了一个视图(self.view addSubview:vista_AS.view])我需要这个来使 tabbar 不可见,后来,当我删除这个视图时,tabbarcontroller 以某种方式丢失了 viewcontroller 0 查看参考。我不明白的是,为什么当我更改为 viewcontroller 1 然后又回到 0 时,视图就可以了。有没有办法重新加载 viewcontroller 0 视图?

更新 2:从建议编辑到答案中包含作者的代码

这是我的代码:

if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation ==        UIInterfaceOrientationLandscapeRight)
{
   self.tabBar.hidden = TRUE;
   vista_AS = [delegate.tabBarController.viewControllers   objectAtIndex:0]; 
   vista_AS.view.frame = CGRectMake(0, 0, 320, 480);
   [self.view addSubview:vista_AS.view];
 }
 else { 
      if ( (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ) 
     {
          [vista_AS.view removeFromSuperview]; 
          self.tabBar.hidden = FALSE; 
     }
4

2 回答 2

0

当您添加vista_AS为 的子视图时,tabBarController您将其父视图更改vista_AS为其最新的视图父视图,因此使用 tabBarController.

当您更改 iPhone 的方向时,您会vista_AS从它的超级视图中删除,但它与您的视图之间的链接tabBarController仍然断开。我相信这就是你看不到风景的原因。vista_AS一个解决方案可能是通过将的父 级重新分配给tabBarController.view或 to do 来解决[tabBarController.view addSubview:vista_AS]

于 2011-02-20T17:52:18.890 回答
0

看来您的视图控制器 1 正在被释放,要么是你自己由于过度释放,要么是系统由于内存而被释放。发布一些代码,显示如何附加和删除覆盖标签栏的视图。这可能是答案。

于 2011-02-18T12:26:09.897 回答