【问题标题】:Different ViewControllers in iOS-Slide-MenuiOS-Slide-Menu 中的不同 ViewController
【发布时间】:2015-10-27 00:01:34
【问题描述】:

我正在使用aryaxt/iOS-Slide-Menu。我的问题是:我需要根据显示的视图控制器显示不同的左侧菜单。这是我在 AppDelegate 中的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
 UserMenuViewController *leftMenu = (UserMenuViewController *) [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"UserMenuViewController"];


    [SlideNavigationController sharedInstance].leftMenu = leftMenu;

当我尝试在我的特殊 ViewController 中更改左侧菜单时,左侧菜单中出现黑屏。

AppDelegate *sharedeDelegate = ((AppDelegate *)[UIApplication sharedApplication].delegate);

    ProfessionalMenuViewController *leftMenu = (ProfessionalMenuViewController *) [sharedeDelegate.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"ProfessionalMenuViewController"];
    [SlideNavigationController sharedInstance].leftMenu = leftMenu;

我尝试了很多东西,但没有任何效果。谢谢!

【问题讨论】:

  • 使 UserMenuViewController *leftMenu 成为 AppDelegate.h 中的一个属性。在 didFinishLaunchingWithOptions 中启动它作为 self.leftMenu = [whatever you want]。在其他视图控制器中,访问 Appdelegate 并将其设置为 sharedDelegate.leftMenu = [whatever]。不过有个问题,你为什么在 AppDelegate 中使用它?为什么不把它作为VC的成员,因为不同VC的功能不同?
  • 如果我从应用程序委托中移动它,我会得到黑屏。
  • @RenanGelrado,你尝试过我的建议了吗?
  • @NSNoob,是的,我做了,但没用。

标签: ios objective-c hamburger-menu


【解决方案1】:

我只知道一种解决方案:

 AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];

SlideNavigationController* landingScreen = (SlideNavigationController*)[mainStoryboard
                                                  instantiateViewControllerWithIdentifier: @"SlideNavigationController"];
LeftMenuViewController *leftMenu = (LeftMenuViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"CVLeftMenuViewController"];

landingScreen.leftMenu = leftMenu;
landingScreen.enableShadow=YES;
landingScreen.enableSwipeGesture = YES;
landingScreen.panGestureSideOffset = 0;

delegate.window.rootViewController = landingScreen;

需要更新 SlideNavigationController 请参阅landingScreen(我在更改语言而不重新启动应用程序时使用)

【讨论】:

    【解决方案2】:

    我建议自定义leftMenuViewController,设置一个全局变量并根据全局变量的值在左侧菜单中显示不同的tableview内容,或者在leftMenuViewController中处理SlideNavigationControllerDidReveal通知并根据当前打开的侧视图控制器添加任何子视图或删除子视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多