J'ai un ViewController qui a une méthode pour concevoir le UINavigationBar, un SubViewController qui hérite de la ViewController et appelle sa méthode de conception et un ShowingViewController et un SecondViewController qui hérite de la SubViewController.Quand dois-je concevoir mon UINavigationBar?
Le ShowingViewController est le contrôleur racine d'un UINavigationController et exécute un Segue « Show » à la SecondViewController. Ils ont à la fois la propriété NSString "presentingProperty". ViewController définit un titelView personnalisé sur la barre de navigation qui affiche la chaîne de propriété.
Ma question: Où dois-je appeler la méthode de conception de ViewController? Lorsque je l'appelle dans viewWillLoad, je ne fonctionnerai pas lorsque je passerai à SecondViewController, car la méthode modifie le NavigationBar du «vieux» DisplayViewController.
Quand je l'appelle dans viewDidLoad, l'utilisateur verra la NavigationBar undesigned avant.
Code de ma méthode de conception:
if (self.navigationController.navigationBar) {
UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 21)];
NSMutableAttributedString *titleText = [[NSMutableAttributedString alloc] initWithString:self.presentingProperty];
[titleText addAttribute: NSForegroundColorAttributeName value: [UIColor whiteColor] range: NSMakeRange(0, self.presentingProperty.length)];
[titleText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Avenir-Heavy" size:21] range:NSMakeRange(0, self.presentingProperty.length)];
[titleLabel setTextAlignment:NSTextAlignmentCenter];
[titleLabel setAttributedText: titleText];
[self.navigationController.navigationBar.topItem setTitleView:titleLabel];
}
Merci pour votre aide.