刷新 TabBarController 上的 ViewController
我有一个 tabBarController ,上面有三个 viewController 。 当选择 viewController 1 并使其旋转 90 度时,我会隐藏 tabBar,并且必须将当前视图添加到 tabBarController 中,否则 tabBar 所在的位置会出现空白。
如果现在我将 iPhone 旋转到之前的方向(垂直正常位置),我将 viewFromSuperview 移除,但视图控制器上没有显示任何视图,我想实际上应该显示原始视图( addsubview 调用之前的视图)如果我选择第二个 viewController,然后返回到 viewController 1,视图将完美显示。
我不明白为什么会发生这种情况,你能帮助我吗?
更新:
我认为问题是我在 tabbarcontroller (self.view addSubview:vista_AS.view]) 上添加了一个视图,我需要这个来使选项卡栏不可见,后来,当我删除这个视图时,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;
}
I have a tabBarController with three viewControllers on it.
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.
If now I rotate the iPhone to the previously orientation (the vertical normal position) I removeFromSuperview the view, but no view is shown on the view controller, I suppose the original view (the one before the addsubview call) should be shown, in fact if I select the second viewController and later I go back to the viewController 1 the view appears perfectly.
I don´t understand why this happens, could you help me?
Update:
I think the problem is that I add a view over the tabbarcontroller (self.view addSubview:vista_AS.view]) I need this to make the tabbar not visible, and later, when I remove this view the tabbarcontroller loses in some way the viewcontroller 0 view reference. What I don´t understand is why when I change to viewcontroller 1 and then back to 0 the view is OK. Is there some way to reload viewcontroller 0 view??
Update 2:
Included author's code from a suggested edit to the answer
This is my code:
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您的视图控制器 1 正在被释放,要么是由于过度释放而被您自己释放,要么是由于内存而被系统释放。发布一些代码,显示如何附加和删除覆盖选项卡栏的视图。这或许就能找到答案。
It appears your view controller 1 is being deallocated, either by yourself due to over releasing or by the system due to memory. Post some code showing how you attach and remove the view covering the tab bar. This may hold the answer.
当您添加
vista_AS
作为tabBarController
的子视图时,您将vista_AS
的父视图更改为其最新的视图父视图,因此用 <代码>tabBarController。当您更改 iPhone 的方向时,您从其超级视图中删除了
vista_AS
,但tabBarController
和您的视图之间的链接仍然损坏。我相信这就是为什么你看不到风景的原因。解决方案可能是通过将vista_AS
的父级重新分配给tabBarController.view
或执行[tabBarController.view addSubview:vista_AS]
。When you add
vista_AS
as a subview of thetabBarController
you change the parent view ofvista_AS
to its newest view parent, therefore breaking the link withtabBarController
.When you change iPhone's orientation, you remove
vista_AS
from its superview, but the link between thetabBarController
and your view it is still broken. I believe that's why you can't see the view. A solution would probably go either by re-assigningvista_AS
's parent totabBarController.view
or to do[tabBarController.view addSubview:vista_AS]
.