私はUINavigationBarを設計するメソッドを持つViewControllerを持っています.UnavigationBarは、ViewControllerを継承し、その設計メソッドと、SubViewControllerを継承するDisplaysViewControllerとSecondViewControllerを呼び出します。私のUINavigationBarはいつデザインするのですか?
ShowViewControllerはUINavigationControllerのルートコントローラであり、SecondViewControllerに対する「表示」セグメントを実行します。 これらは両方ともNSStringプロパティ "presentingProperty"を持っています。 ViewControllerは、プロパティの文字列を表示するナビゲーションバーにカスタムtitelViewを設定します。
私の質問:ViewControllerの設計方法はどこで呼びますか?
viewWillLoadで呼び出すと、メソッドが "古い" ShowingViewControllerのNavigationBarを変更するため、SecondViewControllerに切り替えると機能しません。
私はそれをviewDidLoadで呼び出すと、前に無差別のNavigationBarが表示されます。私の設計方法の
コード:
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];
}
はあなたの助けをいただき、ありがとうございます。