2009-06-19 5 views
1

Mon contrôleur principal est une sous-classe de UITableViewController avec un UIToolBar en bas et, lorsqu'une ligne est sélectionnée, j'aimerais afficher une autre vue sans la barre d'outils. Comment puis-je cacher l'UIToolBar dans la vue enfant? À l'heure actuelle, il est présent dans toutes les vues enfant, à moins qu'elles ne soient créées comme modales.Masquage de UIToolBar pour les vues enfants de UITableViewController

barre d'outils est créée en RootController:

self.toolbar = [[UIToolbar alloc] init]; 
// add tool bar items here 
[self.navigationController.view addSubview:toolbar]; 

RootController affiche ses vues de l'enfant en tant que tel:

UIViewController *controller = [[UIViewController alloc] init...] 
[self.navigationController pushViewController:controller animated:YES]; 

RootController est instancié en tant que telle dans le applicationDidFinishLaunching de délégué app:

RootController *rootcontroller = [[RootController alloc] initWithStyle:UITableViewStyleGrouped]; 
self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootcontroller]; 

[rootcontroller release]; 

[window addSubview:[self.navigationController view]]; 

Si j'ajoute la barre d'outils à [self.view] dans RootControll Au lieu de l'affichage de navigationController, la barre d'outils disparaît complètement.

Répondre

0

Une autre alternative serait d'utiliser "removeFromSuperview"

[barre d'outils removeFromSuperview];

Ensuite, utilisez la méthode viewDidAppear dans la vue où vous souhaitez afficher à nouveau la barre d'outils. Cela fonctionne mieux que viewWillAppear puisque la barre d'outils est ajoutée après l'affichage de la vue. (Pour viewWillAppear, barre d'outils est ajouté au cours de la transition il est donc un peu gênant.)

2

Vous pouvez essayer de masquer la barre d'outils avant d'afficher notre vue enfant avec 'toolbar.hidden = YES', puis dans votre méthode viewWillAppear, affichez-la à nouveau avec 'toolbar. caché = NON '.

0

Je l'ai eu à travailler avec ce

[toolbar removeFromSuperview]; 

Cocher cette

- (void)viewWillAppear:(BOOL)animated 
{ 
[super viewWillAppear:animated]; 

//Initialize the toolbar 
toolbar = [[UIToolbar alloc] init]; 
toolbar.barStyle = UIBarStyleDefault; 

//Set the toolbar to fit the width of the app. 
[toolbar sizeToFit]; 

//Caclulate the height of the toolbar 
CGFloat toolbarHeight = [toolbar frame].size.height; 

//Get the bounds of the parent view 
CGRect rootViewBounds = self.parentViewController.view.bounds; 

//Get the height of the parent view. 
CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds); 

//Get the width of the parent view, 
CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds); 

//Create a rectangle for the toolbar 
CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight); 

//Reposition and resize the receiver 
[toolbar setFrame:rectArea]; 

//Create a button 
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] 
initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(info_clicked:)]; 

[toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]]; 

//Add the toolbar as a subview to the navigation controller. 
[self.navigationController.view addSubview:toolbar]; 



[[self tableView] reloadData]; 

} 

- (void) info_clicked:(id)sender { 


[self.navigationController popViewControllerAnimated:YES]; 
[toolbar removeFromSuperview]; 

} 
Questions connexes