0

In my project using Side menu. It is ready template from gitHub , but the problem is that somtimes searchDisplay controller is work and some times give error , What is actual Problem i am not understad... please help me

side menu template contain this files:
1)JWSlideMenuController
2)JWNavigationController
3)JWSlideMenuViewController

Here the throw error

 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

Here is code for JWNavigationController.h and .m file

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 file

    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

If hide this code from JWNavigationController.m so searchDisplayController is working rootViewController.navigationController = self;

but new problem is UITableVIew didselectrowatindexpath is notworking .. what can i do?

  • It should be UINavigationController instead of UIViewController in JWNavigationController.h file. Reason is isNavigationBarHidden is present in Navigation Controller. Also, if you are using navigation controller, then reason for crash is that JWNavigationViewController you are using is getting removed from memory, i.e. maybe you are removing that object from memory or it is getting release automatically. Try to check above both reasons, some solution will help you get out of this. – P.J Dec 24 '13 at 10:45
  • can u help me other what you told me i m do but its show error 2013-12-23 05:22:28.161 MyProject[764:13d03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot call pushNavigationItem:animated: directly on a UINavigationBar managed by a controller.' *** First throw call stack: (0x197a012 0x1296e7e 0x1979deb 0x258362 0x4361 0x11288 0x28a285 0x28a4ed 0xc945b3 0x1939376 0x1938e06 0x1920a82 0x191ff44 0x191fe1b 0x18d47e3 0x18d4668 0x1daffc 0x5de2 0x1fa5) libc++abi.dylib: terminate called throwing an exception – Binita Modi Dec 24 '13 at 11:26
  • What did you did exactly? Can you paste some code? – P.J Dec 24 '13 at 12:17
  • Also, check this http://stackoverflow.com/questions/2520912/adding-uibarbuttonitem-to-uinav-controller – P.J Dec 24 '13 at 12:19

2 Answers2

0

Your JWNavigationController does not inherit from UINavigationController. But, isNavigationBarHidden is a method implemented by UINavigationController.

Now look at the error (which uses the term 'selector', but that refers to the method): It basically says that the instance of your JWNavigationController does not implement isNavigationBarHidden, and this is the issue.

Could it be that you mistyped, and meant to write:

@interface JWNavigationController : UINavigationController <UINavigationBarDelegate>
meaning-matters
  • 21,929
  • 10
  • 82
  • 142
0

isNavigationBarHidden: is a selector which is only available in classes that derive from UINavigationController. You have to modify this line:

@interface JWNavigationController : UIViewController

with this:

@interface JWNavigationController : UINavigationController
Daniel Martín
  • 7,815
  • 1
  • 29
  • 34