大家好,我尝试使用https://github.com/aryaxt/iOS-Slide-Menu作为我的一个viewcontroller的幻灯片菜单。我阅读了有关幻灯片菜单的文档,这里是我的appdelegate类,didFinishLaunchingWithOptions方法:
- (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)
要点您必须将 isinitViewController 提供给 SlideNavigationController
在 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;
}
在你的HomeController中放置这个委托方法
- (BOOL)slideNavigationControllerShouldDisplayLeftMenu
{
return false;
}
- (BOOL)slideNavigationControllerShouldDisplayRightMenu
{
return YES;
}