在我使用侧边菜单的项目中。它是来自gitHub的准备好的模板,但问题是somtimes searchDisplay控制器是工作有时会给出错误,什么是实际问题我不是底层...请帮帮我
side menu template contain this files:
1)JWSlideMenuController
2)JWNavigationController
3)JWSlideMenuViewController
抛出错误
2013-12-22 13:24:22.671 MyProject[3747:13d03] -[JWNavigationController isNavigationBarHidden]: unrecognized selector sent to instance 0x80c4e60
2013-12-22 13:24:22.681 MyProject[3747:13d03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[JWNavigationController isNavigationBarHidden]: unrecognized selector sent to instance 0x80c4e60'
*** First throw call stack:
(0x1979012 0x1295e7e 0x1a044bd 0x1968bbc 0x196894e 0x4bf326 0x4c0e41 0x410ae4 0x12a9705 0x1dd213 0x29ec7e 0x29e310 0x2aaa31 0x2b3f5f 0x2a21e9 0x2e7d95 0x4ab3c3 0x4ad442 0x4a485a 0x4a399b 0x4a50df 0x4a7d2d 0x4a7cac 0x49fa28 0x20c972 0x20ce53 0x1ead4a 0x1dc698 0x18d4df9 0x18d4ad0 0x18eebf5 0x18ee962 0x191fbb6 0x191ef44 0x191ee1b 0x18d37e3 0x18d3668 0x1d9ffc 0x5da2 0x1f65)
libc++abi.dylib: terminate called throwing an exception
这是JWNavigationController.h和.m文件的代码
JWNavigationController.h
#import <UIKit/UIKit.h>
@class JWSlideMenuController;
@interface JWNavigationController : UIViewController <UINavigationBarDelegate>
@property (nonatomic, retain) UINavigationBar *navigationBar;
@property (nonatomic, retain) UIView *contentView;
@property (nonatomic, retain) JWSlideMenuController *slideMenuController;
@property (nonatomic, retain, readonly) UIViewController *rootViewController;
- (id)initWithRootViewController:(UIViewController *)rootViewController;
- (void)pushViewController:(UIViewController *)controller;
- (UIViewController *)popViewController;
@end
JWNavigationController.m文件
JWNavigationController.m
// JWNavigationController.m
// JWSlideMenu
//
// Created by Jeremie Weldin on 11/22/11.
// Copyright (c) 2011 Jeremie Weldin. All rights reserved.
//
#import "JWNavigationController.h"
#import "JWSlideMenuViewController.h"
@interface JWNavigationController(Private)
-(UIViewController*)removeTopViewController;
@end
@implementation JWNavigationController
@synthesize navigationBar;
@synthesize contentView;
@synthesize slideMenuController;
@synthesize rootViewController=_rootViewController;
#pragma mark - View lifecycle
- (id)init
{
self = [super init];
if (self) {
CGRect masterRect = [[UIScreen mainScreen] bounds];
CGRect contentFrame = CGRectMake(0.0, 44.0, masterRect.size.width, masterRect.size.height - 44.0);
CGRect navBarFrame = CGRectMake(0.0, 0.0, masterRect.size.width, 44.0);
self.view = [[[UIView alloc] initWithFrame:masterRect] autorelease];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.view.backgroundColor = [UIColor whiteColor];
self.contentView = [[[UIView alloc] initWithFrame:contentFrame] autorelease];
self.contentView.backgroundColor = [UIColor whiteColor];
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:self.contentView];
self.navigationBar = [[[UINavigationBar alloc] initWithFrame:navBarFrame] autorelease];
self.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.navigationBar.delegate = self;
[self.view insertSubview:self.navigationBar aboveSubview:self.contentView];
self.navigationBar.backgroundColor=[UIColor whiteColor];
}
return self;
}
- (id)initWithRootViewController:(JWSlideMenuViewController *)rootViewController
{
self = [self init];
if(self) {
_rootViewController = rootViewController;
UIBarButtonItem *menuButton = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"menu_icon_20x20.png"] style:UIBarButtonItemStyleBordered target:self.slideMenuController action:@selector(toggleMenu)] autorelease];
rootViewController.navigationItem.leftBarButtonItem = menuButton;
[self addChildViewController:rootViewController];
[self.contentView addSubview:rootViewController.view];
[self.navigationBar pushNavigationItem:rootViewController.navigationItem animated:YES];
rootViewController.navigationController = self;
}
return self;
}
#pragma mark - UINavigationBarDelegate
- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item
{
UIViewController *controller = [self.childViewControllers lastObject];
if (item==controller.navigationItem) //Will now called only if a back button pop happens, not in manual pops
{
[self removeTopViewController];
}
}
- (void)navigationBar:(UINavigationBar *)navigationBar didPushItem:(UINavigationItem *)item
{
}
#pragma mark - Stack Interaction
- (void)pushViewController:(JWSlideMenuViewController *)controller
{
[self addChildViewController:controller];
[self.navigationBar pushNavigationItem:controller.navigationItem animated:YES];
controller.navigationController = self;
controller.view.frame = self.contentView.bounds;
if([self.childViewControllers count] == 1)
{
[self.contentView addSubview:controller.view];
}
else
{
UIViewController *previousController = [self.childViewControllers objectAtIndex:[self.childViewControllers count]-2];
[self transitionFromViewController:previousController toViewController:controller duration:0.5 options:UIViewAnimationOptionTransitionNone animations:NULL completion:NULL];
}
}
- (UIViewController *)popViewController
{
//Can use this to pop manually rather than back button alone
UIViewController *controller = [self.childViewControllers lastObject];
UIViewController *previousController = nil;
if([self.childViewControllers count] > 1)
{
previousController = [self.childViewControllers objectAtIndex:[self.childViewControllers count]-2];
previousController.view.frame = self.contentView.bounds;
}
[self transitionFromViewController:controller toViewController:previousController duration:0.3 options:UIViewAnimationOptionTransitionNone animations:NULL completion:NULL];
[controller removeFromParentViewController];
if(self.navigationBar.items.count > self.childViewControllers.count)
[self.navigationBar popNavigationItemAnimated:YES];
return controller;
}
- (void)viewDidUnload
{
_rootViewController = nil;
self.navigationBar = nil;
self.contentView = nil;
self.slideMenuController = nil;
[super viewDidUnload];
}
- (void)dealloc {
[_rootViewController release];
[navigationBar release];
[contentView release];
[super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(UIViewController*)removeTopViewController
{
UIViewController *controller = [self.childViewControllers lastObject];
UIViewController *previousController = nil;
if([self.childViewControllers count] > 1)
{
previousController = [self.childViewControllers objectAtIndex:[self.childViewControllers count]-2];
previousController.view.frame = self.contentView.bounds;
}
[self transitionFromViewController:controller toViewController:previousController duration:0.3 options:UIViewAnimationOptionTransitionNone animations:NULL completion:NULL];
[controller removeFromParentViewController];
return controller;
}
@end
如果从JWNavigationController.m隐藏此代码,那么searchDisplayController正在运行 rootViewController.navigationController = self;
但新问题是UITableVIew didselectrowatindexpath不工作..我该怎么办?
答案 0 :(得分:0)
您的JWNavigationController
未从UINavigationController
继承。
但是,isNavigationBarHidden
是由UINavigationController
实施的方法。
现在看一下错误(使用术语'选择器',但是指的是方法):它基本上表示JWNavigationController
的实例没有实现isNavigationBarHidden
,这是这个问题。
可能是你错误输入,并打算写:
@interface JWNavigationController : UINavigationController <UINavigationBarDelegate>
答案 1 :(得分:0)
isNavigationBarHidden:
是一个选择器,仅在派生自UINavigationController
的类中可用。你必须修改这一行:
@interface JWNavigationController : UIViewController
用这个:
@interface JWNavigationController : UINavigationController