UINavigationController を継承するクラスを定義し、このクラスにボタンを追加することは可能ですか?このクラスを別のクラスで使用するたびに、各クラスのナビゲーションバーにボタンが表示されます..明確であることを願っています.事前に感謝します
1 に答える
UINavigationController を使用する代わりに、UIViewController をサブクラス化し、このクラスで必要なものを構成することをお勧めします。
さらに、同じ実装が必要な場合は、新しく作成したクラスを使用してください。
例えば; 以下のように新しい CustomViewController を作成します
.h ファイル内
@interface CustomViewController : UIViewController { }
.m ファイルで、
-(void)viewDidLoad { [super viewDidLoad];
// 要件に応じたバーとビューのカスタム実装 }
Now if you want to have this configuration in some other View Controller, subclass CustomViewController and everything will be done. Eg: If you have ListViewController,
in .h file,
@interface ListViewController : CustomViewController { }
in .m file
-(void)viewDidLoad { [super viewDidLoad]; // Its super class is "CustomViewController" so viewDidLoad method you implemented in CustomViewController will be called and your view will be configured.
// Further Whatever you want in this controller }
Hope it helps.