Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "unrecognized selector sent to instance"?

I have a problem with the second app tutorial at apple tut site. In the main class i get an error.

The code:

#import "birdwatchingAppDelegate.h"

int main(int argc, char *argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([birdwatchingAppDelegate class]));
     } }

Error:

[birdwatchingViewController viewControllers]: unrecognized selector
sent to instance 0x6d37000'

The following is where the location of the error:

import "birdwatchingAppDelegate.h"
        #import "BirdSightingDataController.h"
        #import "birdwatchingViewController.h"

        @implementation birdwatchingAppDelegate

        @synthesize window = _window, dataController = _dataController, firstViewController = _firstViewController;

        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
        {
            UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
            birdwatchingViewController *firstViewController = (birdwatchingViewController *)[[navigationController
    viewControllers] objectAtIndex:0];

            BirdSightingDataController *aDataController = [[BirdSightingDataController alloc] init];
            firstViewController.dataController = aDataController;

            return YES;
        }

and the exact line that causes problems is:

birdwatchingViewController *firstViewController = (birdwatchingViewController *)[[navigationController
    viewControllers] objectAtIndex:0];

i can't locate the problem, can somebody help?

thanks..

EDIT:

By adding the NSlog i got following:

2012-02-10 11:24:06.059 Birdwatching[3057:f803] birdwatchingViewController
2012-02-10 11:24:06.060 Birdwatching[3057:f803] -[birdwatchingViewController viewControllers]: unrecognized selector sent to instance 0x6878250

EDIT based on comment :

2012-02-10 11:51:20.696 Birdwatching[3152:f803] navi : <birdwatchingViewController: 0x6a49c20>
like image 744
Roskvist Avatar asked Feb 01 '26 06:02

Roskvist


1 Answers

it's because self.window.rootViewController is not a UINavigationController it might be simple UIViewcontroller


Edited based upon log
change your method to

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
        {
            birdwatchingViewController *firstViewController = (birdwatchingViewController *)self.window.rootViewController;

            BirdSightingDataController *aDataController = [[BirdSightingDataController alloc] init];
            firstViewController.dataController = aDataController;

            return YES;
        }
like image 165
Inder Kumar Rathore Avatar answered Feb 03 '26 20:02

Inder Kumar Rathore