1

Not too sure how to debug this.

2013-01-24 20:36:18.448 SlideMenu[2069:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[initViewController viewControllers]: unrecognized selector sent to instance 0xac6cdb0'

Here's initViewController.m

#import "initViewController.h"
#import "ECSlidingViewController.h"
#import "MenuViewController.h"

@interface initViewController ()

@end

@implementation initViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Main"];
}

@end

And where the exception is being thrown:

AppDelegate.m

#import "AppDelegate.h"
#import "MainViewController.h"
#import "ListDoc.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ListDoc *list1 = [[ListDoc alloc] initWithTitle:@"Potato Bug" thumbImage:[UIImage imageNamed:@"potatoBugThumb.jpg"]];
    ListDoc *list2 = [[ListDoc alloc] initWithTitle:@"House Centipede" thumbImage:[UIImage imageNamed:@"centipedeThumb.jpg"]];
    NSMutableArray *lists = [NSMutableArray arrayWithObjects:list1,list2,nil];

    UINavigationController * navController = (UINavigationController *) self.window.rootViewController;
    MainViewController * mainController = [navController.viewControllers objectAtIndex:0];
    mainController.someData = lists;
    // Override point for customization after application launch.
    return YES;
}

@end
Cœur
  • 37,241
  • 25
  • 195
  • 267
STANGMMX
  • 973
  • 7
  • 18
  • 31
  • Look in your code for something that's calling the `viewControllers` method of some object. It appears to be targeting the **wrong** object. – Phillip Mills Jan 27 '13 at 20:23
  • 2
    Add an exception breakpoint to see where the call to the non-existing `viewControllers` method is coming from. Go to the breakpoint navigator in Xcode (cmd+6), then click "+" at the bottom and select "Add Exception Breakpoint…". – omz Jan 27 '13 at 20:23
  • `assert([navController isKindOfClass:[UINavigationController class]]);` – Daij-Djan Jan 27 '13 at 20:33
  • @Daij-Djan Sorry you'll have to be more specific. Not familiar with assert() – STANGMMX Jan 27 '13 at 20:41
  • assert is an fail if condition is untrue. Im trying to confirm PhillipMills idea that you don't really DEAL with a navController! – Daij-Djan Jan 27 '13 at 20:46
  • Possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](https://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Cœur Jul 08 '19 at 05:51

1 Answers1

3

From Your Post :

2013-01-24 20:36:18.448 SlideMenu[2069:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[initViewController viewControllers]: unrecognized selector sent to instance 0xac6cdb0'

Found where the exception is being thrown:

UINavigationController * navController = (UINavigationController *) self.window.rootViewController;  
MainViewController * mainController = [navController.viewControllers objectAtIndex:0];

Here is my reading of that : The item navControlleris an instance of initViewController and this is probably not what you are expecting.
initViewController is probably not a subclass of UINavigationController.

How To Debug ? Try This :
NSLog(@"%@", [navController class]);

Vincent Bernier
  • 8,674
  • 4
  • 35
  • 40