我有一個視圖控制器具有設計UINavigationBar的,它從視圖控制器繼承並調用它的設計方法和ShowingViewController和SecondViewController從SubViewController繼承SubViewController的方法。什麼時候應該設計我的UINavigationBar?
ShowingViewController是UINavigationController的根控制器,並執行「顯示」塞格到SecondViewController。 它們都具有NSString屬性「presentingProperty」。 ViewController將自定義titelView設置爲顯示屬性字符串的導航欄。
我的問題:我應該在哪裏調用視圖控制器的設計方法?
當我把它稱爲viewWillLoad,當我切換到SecondViewController因爲該方法改變了「老」 ShowingViewController的導航欄,我將無法正常工作。
當我把它在viewDidLoad中,用戶將看到之前的非故意導航欄。
我的設計方法的代碼:
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];
}
謝謝您的幫助。