他のすべてのView Controllerによって継承されたBaseViewControllerを作成する必要があります。また、他のすべてのView Controllerで使用できるBaseViewControllerに必要なメソッドを追加できます。
例:
これは他のすべてのクラスのスーパークラスになります。あなたが他のすべてのビューコントローラでMenuBaseViewControllerを継承し、メニューを表示または非表示にshowMenu/hideMenuメソッドを呼び出す必要が同じように
MenuBaseViewController.h
————————————————————————————
@interface MenuBaseViewController : UIViewController
//declare properties and methods here
- (void)showMenu;
- (void)hideMenu;
@end
MenuBaseViewController.m
————————————————————————————
@implementation MenuBaseViewController
//implement methods here
- (void)showMenu {
//logic for showing menu
//probably you need to set rootViewController what is selected.
//You can create method for setting root view controller in AppDelegate
}
- (void)hideMenu {
//logic for hiding menu
}
@end
OneViewController.h
————————————————————————————
@interface OneViewController : MenuBaseViewControlle
//declare properties and methods here
@end
OneViewController.m
————————————————————————————
@implementation MenuBaseViewController
//implement methods here
//you can call showMenu, hideMenu to show/hide menu
@end
。
これは、実行する方法がわからないことです。 –
編集を参照してください。私はそれをどのように実装することができるかを考えてみました。 –
コードを書いていただきありがとうございます。私はこれをどうやって行うのか考えている。私は前にこれを試してみました。しかし、私が直面した問題は、ViewControllerは共通クラスで作成されたボタンのアクションを実行できませんでした。メニューを表示したり、メニューを隠したりするのは簡単です。しかし、サイドメニューの要素との相互作用は不可能でした。 –