Refresh ViewController on TabBarController
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;
开发者_JAVA百科 }
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.
When you add vista_AS
as a subview of the tabBarController
you change the parent view of vista_AS
to its newest view parent, therefore breaking the link with tabBarController
.
When you change iPhone's orientation, you remove vista_AS
from its superview, but the link between the tabBarController
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-assigning vista_AS
's parent to tabBarController.view
or to do [tabBarController.view addSubview:vista_AS]
.
精彩评论