在appdelegate类中添加tab bar viewcontroller和DDMenuController

Posted

技术标签:

【中文标题】在appdelegate类中添加tab bar viewcontroller和DDMenuController【英文标题】:Add tab bar viewcontroller and DDMenuController in the appdelegate class 【发布时间】:2014-03-17 06:59:14 【问题描述】:

我想为应用添加 DDMenuController 和标签栏视图控制器。 我无法同时添加两者,所以请帮我解决这个问题。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    // Override point for customization after application launch.

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
    HomeViewController *mainViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];

    navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
    navigationController.delegate = self;
    DDMenuController *rootController = [[DDMenuController alloc] initWithRootViewController:navigationController];
    _menuController = rootController;

    MenuListViewController *menuController = [[MenuListViewController alloc]init];
    rootController.rightViewController = menuController;


    TabbarViewController *tabBarVC  = [[TabbarViewController alloc] init];
    tabBarVC.viewControllers = [NSArray arrayWithObjects:rootController, nil];

    if ([tabBarVC respondsToSelector:@selector(willAppearIn:)])
    
        [tabBarVC performSelector:@selector(willAppearIn:) withObject:navigationController];
    

    self.window.rootViewController = tabBarVC;
    [self.window makeKeyAndVisible];

    return YES;

感谢您的帮助...

【问题讨论】:

你想添加第一个工具栏,而不是在一个选项卡中添加 DDMenuController 之后? @YashpalJavia 我希望两者都应该出现在整个应用程序中。 【参考方案1】:

我认为这会有所帮助。

首先创建标签栏而不是添加DDMenuController,最后添加到窗口的根视图

这可能有效。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    // Override point for customization after application launch.

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
    HomeViewController *mainViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];

    navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
    navigationController.delegate = self;


    TabbarViewController *tabBarVC  = [[TabbarViewController alloc] init];
    tabBarVC.viewControllers = [NSArray arrayWithObjects:rootController, nil];

    if ([tabBarVC respondsToSelector:@selector(willAppearIn:)])
    
        [tabBarVC performSelector:@selector(willAppearIn:) withObject:navigationController];
    



    DDMenuController *rootController = [[DDMenuController alloc] initWithRootViewController:tabBarVC];
    _menuController = rootController;

    MenuListViewController *menuController = [[MenuListViewController alloc]init];
    rootController.rightViewController = menuController;



    self.window.rootViewController = rootController;
    [self.window makeKeyAndVisible];

    return YES;

编辑:

这是视图控制器的序列。

navigationViewController -> rootViewController -> 主 ViewController(这是你的默认设置)

tabbar -> rootViewController -> navigationViewController(如果你想要很多,你可以在 tabbarViewController 中放很多视图)

manuViewController(DDMenuController 显示在右侧)

DDMenuController -> rootViewController -> 标签栏

DDMenuController -> rightController -> manuViewController

窗口 -> 根视图控制器 -> DDMenuController

【讨论】:

以上是关于在appdelegate类中添加tab bar viewcontroller和DDMenuController的主要内容,如果未能解决你的问题,请参考以下文章

将TAB BAR添加到uitableviewcontroller [关闭]

Tab Bar Controller + Navigation Controller + Bar Button Item

Tab Bar 子 viewWillAppear 不会触发,添加 NavigationController 会给出两个导航栏

IOS禁用Tab bar顶部的触摸区域

《iOS Human Interface Guidelines》——Tab Bar

uniapp中使用微信小程序custom-tab-bar