2016-10-01 41 views
0

大家好我尝试使用https://github.com/aryaxt/iOS-Slide-Menu作为我的一个viewcontroller的幻灯片菜单。我读到滑动菜单中的文档,这里是我的AppDelegate类,didFinishLaunchingWithOptions方法:使用iOS-Slide-Menu的iphone幻灯片菜单

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

[StyleKit setupAppearance]; 

ListViewController *controller = [ListViewController new]; 
    _navigationController = [[UINavigationController alloc] 
    initWithRootViewController:controller]; 
RightViewController *rightMenu = [RightViewController new]; 

[SlideNavigationController sharedInstance].rightMenu = rightMenu; 
[SlideNavigationController sharedInstance].menuRevealAnimationDuration = .18; 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
// Override point for customization after application launch. 
self.window.backgroundColor = [UIColor whiteColor]; 
self.window.rootViewController = _navigationController; 
[self.window makeKeyAndVisible]; 

[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidClose object:nil queue:nil usingBlock:^(NSNotification *note) { 
    NSString *menu = note.userInfo[@"menu"]; 
    NSLog(@"Closed %@", menu); 
}]; 

[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidOpen object:nil queue:nil usingBlock:^(NSNotification *note) { 
    NSString *menu = note.userInfo[@"menu"]; 
    NSLog(@"Opened %@", menu); 
}]; 

[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidReveal object:nil queue:nil usingBlock:^(NSNotification *note) { 
    NSString *menu = note.userInfo[@"menu"]; 
    NSLog(@"Revealed %@", menu); 
}]; 
return YES; 
} 

我要显示在“ListViewController”滑动菜单,以便为文档说我实现了我的头文件是这样的:

// 
// ListViewController.h 

#import <UIKit/UIKit.h> 
#import "SlideNavigationController.h" 
@interface ListViewController :   
UIViewController<SlideNavigationControllerDelegate> 
@end 
// ListViewController.m 
//Some code... 
- (void)setupActions { 
[self.listView.tableHeaderView.followButton addTarget:self"          
action:@selector(didTapFollowButton:)       
forControlEvents:UIControlEventTouchUpInside]; 

[self.fakeNavigationController.menuButton addTarget: 
[SlideNavigationController sharedInstance] 
action:@selector(toggleRightMenu) 
forControlEvents:UIControlEventTouchUpInside]; 

} 

- (BOOL)slideNavigationControllerShouldDisplayLeftMenu 
    { 
    return NO; 
    } 

    - (BOOL)slideNavigationControllerShouldDisplayRightMenu 
    { 
    return YES; 
} 

但是,当我启动应用程序时,我得到这个错误: SlideNavigationController尚未初始化。将其中一个放入故事板,或者用代码初始化一个。

请等待你的帮助,感谢小号:)

+0

你在你的故事板添加视图控制器?如果没有,然后添加它,并将其设置为初始视图控制器 –

+0

我没有故事板... @ ravi.p – phantom

回答

0

要点你必须isinitViewControllerSlideNavigationController

导入此行AppDelegate.h文件

#import "SlideNavigationController.h" 
#import "LeftMenuViewController.h" 
#import "RightMenuViewController.h" 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" 
                  bundle: nil]; 
    RightMenuViewController *rightMenu = (RightMenuViewController*)[mainStoryboard 
                  instantiateViewControllerWithIdentifier: @"RightMenuViewController"]; 
    [SlideNavigationController sharedInstance].rightMenu = rightMenu; 
    [SlideNavigationController sharedInstance].menuRevealAnimationDuration = .18; 
// Creating a custom bar button for right menu 
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; 
    [button setImage:[UIImage imageNamed:@"gear"] forState:UIControlStateNormal]; 
    [button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu) forControlEvents:UIControlEventTouchUpInside]; 
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 
    [SlideNavigationController sharedInstance].rightBarButtonItem = rightBarButtonItem; 
    [[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidClose object:nil queue:nil usingBlock:^(NSNotification *note) { 
     NSString *menu = note.userInfo[@"menu"]; 
     NSLog(@"Closed %@", menu); 
    }]; 
[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidOpen object:nil queue:nil usingBlock:^(NSNotification *note) { 
     NSString *menu = note.userInfo[@"menu"]; 
     NSLog(@"Opened %@", menu); 
    }]; 
[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidReveal object:nil queue:nil usingBlock:^(NSNotification *note) { 
     NSString *menu = note.userInfo[@"menu"]; 
     NSLog(@"Revealed %@", menu); 
    }]; 
    return YES; 
} 

在你的HomeCon troller把这个代表法

编译马克 - SlideNavigationController方法 -

- (BOOL)slideNavigationControllerShouldDisplayLeftMenu 
{ 
    return false; 
} 

- (BOOL)slideNavigationControllerShouldDisplayRightMenu 
{ 
    return YES; 
} 
+0

其实,我的homecontroller不是我的初始视图控制器,我的意思是:我想添加幻灯片视图的控制器是初始视图控制器 – phantom

+0

在你的storyborad初始视图控制器中,你必须给一个SlideNavigationController,然后你的下一个控制器就是你的第一个控制器,就像任何UIVIewController一样。 –

+0

我不使用故事板。 – phantom