无法识别的选择器发送到实例

时间:2013-01-27 20:18:44

标签: ios objective-c exception

不太清楚如何调试这个。

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'

这是initViewController.m

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

@interface initViewController ()

@end

@implementation initViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

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

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

坦率地说,我甚至不确定这段代码中是否会抛出异常。谢谢你的帮助

编辑:

找到抛出异常的位置:

    NSMutableArray *lists = [NSMutableArray arrayWithObjects:list1,list2,list3,list4,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;
}

编辑2:

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"]];
    ListDoc *list3 = [[ListDoc alloc] initWithTitle:@"Wolf Spider" thumbImage:[UIImage imageNamed:@"wolfSpiderThumb.jpg"]];
    ListDoc *list4 = [[ListDoc alloc] initWithTitle:@"Lady Bug" thumbImage:[UIImage imageNamed:@"ladybugThumb.jpg"]];
    NSMutableArray *lists = [NSMutableArray arrayWithObjects:list1,list2,list3,list4,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;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

1 个答案:

答案 0 :(得分:3)

来自你的帖子:

  

2013-01-24 20:36:18.448 SlideMenu [2069:c07] * 终止应用程序   未捕获的异常'NSInvalidArgumentException',原因:   ' - [initViewController viewControllers]:发送到的无法识别的选择器   实例0xac6cdb0'

找到抛出异常的位置:

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

以下是我对此的解读: 项navControllerinitViewController的实例,这可能不是您所期望的 initViewController可能不是UINavigationController的子类。

如何调试?试试这个:
NSLog(@"%@", [navController class]);