2012-02-06 14 views
5

soy nuevo en la programación de iOS. En serio necesito tu ayuda.mostrar/ocultar la barra de pestañas cuando sea necesario desde un controlador de vista

tengo una pantalla de inicio de sesión que me lleva a un mapa (API de Google). Al hacer clic en cualquier anotación creada, quiero cargar una barra de pestañas con 2 vistas.

busqué y descubrí que tengo que agregar la barra de tareas en el inicio, es decir, el delegado de la aplicación y mostrar/ocultar la barra de tabulación cuando sea necesario.

así que hice 2 funciones para mostrar y ocultar barra de pestañas como

-(void)Load_tabBar{ 
[self.navigationController.view removeFromSuperview]; 
[self.window addSubview:tabBarController.view]; 
[self.window makeKeyWindow];} 

-(void)remove_tabBar{ 
self.tabBarController.selectedIndex=0; 
[self.tabBarController.view removeFromSuperview]; 
[self.window addSubview:navigationController.view]; 
[self.window makeKeyWindow];} 

lo hizo el trabajo cuando llamo el método Load_tabBar y cuando hago clic en la espalda se llama al método remove_tabBar. si un nuevo llamamiento Load_tabBar método y la espalda, se bloquea el error de dar

- [ventana UILayoutContainerView]: mensaje enviado a la instancia desasignado 0x563b0b0

editado: PS: ¿Puedo añadir la vista de barra de pestañas a un controlador de vista y luego empuje que ¿ver?

thnx

Respuesta

8

uso de este self.hidesBottomBarWhenPushed = YES;

+0

añade bt siendo el mismo :( –

+0

puedo añadir la vista de barra de pestañas a un controlador de vista y luego empujar ese punto de vista –

+0

cuando estás? Al presionar el controlador de vista en ese controlador de visualización de presentación, debe agregar esto en el método viewWillAppear. No necesita usar su código – Tendulkar

1

espero que estos dos métodos pueden ayudarle,

- (void) hideTabBar:(UITabBarController *) tabbarcontroller { 

int height = 480; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.3]; 

for(UIView *view in tabbarcontroller.view.subviews) { 
    if([view isKindOfClass:[UITabBar class]]) { 
     [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)]; 
    } 
    else { 
     [view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)]; 
    } 
} 
[UIView commitAnimations]; 

}

- (void) showTabBar:(UITabBarController *) tabbarcontroller { 

int height = 480; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.3]; 

for(UIView *view in tabbarcontroller.view.subviews) { 

    if([view isKindOfClass:[UITabBar class]]) { 
     [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];    
    } 
    else { 
     [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)]; 
    } 
}  

[UIView commitAnimations]; 

}

Simplemente coloque estos dos métodos en la clase AppDelegate y llámelos siempre que lo requiera según sus necesidades.

+0

No quiero cambiar el tamaño del marco de las subvistas. cuando aparece, aparece en otra vista en conjunto ... las subvistas también se han ido –

+0

y luego simplemente estableces los tamaños que necesitas !!!! –

+0

Parece que funciona bien, he agregado algunos ajustes para manejar tanto el iPhone como el iPad. obtener ancho y alto de la ventana como altura flotante = self.window.frame.size.height; ancho de flotante = self.window.frame.size.width; – Sheepdogsheep

1

Este método definitivamente funciona. Sólo tiene que poner en el método antes de que lo empuje, así:

-actionThatPushTheViewController { 

    //create the view controller here, do some init. 

    //then: 
    theViewControllerToBePushed.hidesBottomBarWhenPushed = YES; 

    //push it here like this: 
    [self.navigationController pushViewController:theViewControllerToBePushed animated:YES]; 
Cuestiones relacionadas