2012-01-16 13 views
5

tengo algunas dificultades para cambiar los controles de barra de pestañas. Básicamente tengo UITabBarController con 3 controladores. La primera vez que se inicia la aplicación. Cambio un controlador como este:UItabBar cambiar controladores de vista

NSMutableArray *muteArray = [[NSMutableArray alloc] init]; 
FirstPage *online; 

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{ 

    online =[[FirstPage alloc] initWithNibName:nil bundle:nil]; 


}else{ 

    online =[[FirstPage alloc] initWithNibName:nil bundle:nil]; 
} 

//adding all controllers of tab bar to array 
[muteArray addObjectsFromArray:_navigationCotroller.viewControllers]; 
online.tabBarControllers = [muteArray copy]; 
//replacing object of login controller to after login controller 
[muteArray replaceObjectAtIndex:1 withObject:online]; 


[online release]; 

//setting new controllers to tab bar 
[_navigationCotroller setViewControllers:muteArray animated:YES]; 

[muteArray release]; 

Luego en el controlador FirstPage hago algunos cambios y presiono OK. Ahora tengo que cambiar los controladores de nuevo, haciendo esto:

NSLog(@"Before change Tab Bar cotrollers = %@",self.tabBarController.viewControllers); 

[self.tabBarController setViewControllers:_tabBarControllers animated:YES]; 

NSLog(@"After change Tab Bar cotrollers = %@",self.tabBarController.viewControllers); 

[self.tabBarController.tabBarController setSelectedIndex:1]; 

_tabBarControllers es gama de controladores, que me salvó cuando se inició la aplicación.

Este código cambia los controladores, pero cuando quiero abrir el controlador cambiado con setSelectedIndex no funciona.

¿Alguna idea?

e imprimir este:

Antes cotrollers cambio Tab Bar = NULL Después del cambio de la barra de pestañas cotrollers = NULL

+0

_navigationCotroller es un error ortográfico en el código también? –

+0

_navigationCotroller es el principal UITabBarController – Streetboy

+0

tenga en cuenta el carácter "N" que falta allí;) _navigationCotroller -> _navigationCoNtroller –

Respuesta

10

Primero suponer que quería decir:

[self.tabBarController setSelectedIndex:1]; 

De no ser así suena como el problema es con tus _tabBarControllers.

lo haga el siguiente resultado:

NSLog(@" _tabBarControllers count = %d", [_tabBarControllers count]); 
NSArray* newArray = [NSArray arrayWithArray:self.tabBarController.viewControllers]; 
NSLog(@" newArray count = %d", [newArray count]); 

EDIT: hace lo siguiente elimina con éxito la primera pestaña sin ningún problema?

NSMutableArray* newArray = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers]; 
[newArray removeObjectAtIndex:0]; 
[self.tabBarController setViewControllers:newArray animated:YES]; 

EDIT 2:

pruebe a cambiar:

[muteArray addObjectsFromArray:_navigationCotroller.viewControllers]; 
online.tabBarControllers = [muteArray copy]; 
[muteArray replaceObjectAtIndex:1 withObject:online]; 

a:

[muteArray addObjectsFromArray:self.tabBarController.viewControllers]; 
[muteArray replaceObjectAtIndex:1 withObject:online]; 
online.tabBarControllers = [muteArray copy]; 

para ser honesto me resulta difícil seguir la estructura de su aplicación y de referencias a objetos .

+0

_tabBarControllers = 3 newArray count = 3 y Antes de cambiar la barra de pestañas cotrollers = ( "", "", "" ) Después del cambio de la barra de pestañas cotrollers = (null) – Streetboy

+0

Sin ver su código donde se crea _tabBarControll es difícil ayudar. – ader

+0

existe el código anterior: online.tabBarControllers = [muteArray copy]; aquí copio todos los controladores creados por defecto. – Streetboy

Cuestiones relacionadas