2015-10-27 50 views
1

我正在使用aryaxt/iOS-Slide-Menu。我的問題是:我需要顯示不同的左側菜單,具體取決於顯示哪個視圖控制器。這是我在的AppDelegate代碼:iOS-Slide-Menu中的不同ViewControllers

- (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; 

我試了很多東西,但沒有奏效。謝謝!

+0

讓UserMenuViewController * leftMenu在AppDelegate.h的屬性。在didFinishLaunchingWithOptions中啓動它爲self.leftMenu = [任何你想要的]。在其他ViewController中,訪問Appdelegate並將其設置爲sharedDelegate.leftMenu = [whatever]。儘管如此,你爲什麼在AppDelegate中使用它?爲什麼不把它用作風險投資的成員,因爲不同風險投資的功能是不同的? – NSNoob

+0

如果我從應用程序代理移動它,我會看到黑屏。 –

+0

@RenanGelrado,你試過我的建議嗎? – NSNoob

回答

3

我知道只有一個解決辦法:

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(我使用時,無需重新啓動應用程序切換語言)

0

我建議自定義leftMenuViewController,設置一個全局變量並根據全局變量的值在左側菜單中顯示不同的tableview內容,或者在leftMenuViewController中處理SlideNavigationControllerDidReveal通知,並根據當前打開的側視圖控制器添加任何子視圖或刪除子視圖。

相關問題