Soft Line
Soft Line

Reputation: 37

unrecognized selector sent to instance XCODE

I have a dynamic table and when a try start to emulator, I can't. This I does with a exapmple and I don't repair it.

 EscarabajoFeoDoc *bug1 = [[EscarabajoFeoDoc alloc] initWithTitle:@"Escarabajo Patatero" rating:4 thumbImage:[UIImage imageNamed:@"potatoBugThumb.png"] fullImage:[UIImage imageNamed:@"potatoBug.png"]];
    EscarabajoFeoDoc *bug2 = [[EscarabajoFeoDoc alloc] initWithTitle:@"Cienpiés" rating:3 thumbImage:[UIImage imageNamed:@"centipedeThumb.png"] fullImage:[UIImage imageNamed:@"centipede.png"]];
    EscarabajoFeoDoc *bug3 = [[EscarabajoFeoDoc alloc] initWithTitle:@"Araña Lobo" rating:5 thumbImage:[UIImage imageNamed:@"wolfSpiderThumb.png"] fullImage:[UIImage imageNamed:@"wolfSpider.png"]];
    EscarabajoFeoDoc *bug4 = [[EscarabajoFeoDoc alloc] initWithTitle:@"Mariquita" rating:1 thumbImage:[UIImage imageNamed:@"ladybugThumb.png"] fullImage:[UIImage imageNamed:@"ladybug.png"]];
    NSMutableArray *arrBugs = [NSMutableArray arrayWithObjects:bug1, bug2, bug3, bug4, nil];

    UINavigationController *navController = (UINavigationController *) self.window.rootViewController;
    MasterViewController *masterController = [navController.viewControllers objectAtIndex:0];
    masterController.arrEscarabajos = arrBugs;

The next one I show the error:

 2014-11-19 12:11:45.752 Golf Tipp[3280:60b] -[MasterViewController viewControllers]: unrecognized selector sent to instance 0x8c24400
2014-11-19 12:11:45.755 Golf Tipp[3280:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MasterViewController viewControllers]: unrecognized selector sent to instance 0x8c24400'
*** First throw call stack:
(
    0   CoreFoundation                      0x018291e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x015a88e5 objc_exception_throw + 44
    2   CoreFoundation                      0x018c6243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Upvotes: 0

Views: 477

Answers (1)

Sagarika
Sagarika

Reputation: 36

you have written this line

UINavigationController *navController = (UINavigationController *) self.window.rootViewController;
you are expecting window's rootviewcontroller as navigation controller but it is returning uiviewcontroller.
as a result when u are calling navController.viewControllers , application is raising an exception.
because pointer is of UINavigationController but object inside is of UIViewController

to solve the problem

replace below lines of your code

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

with

MasterViewController *masterController = self.window.rootViewController;

Upvotes: 1

Related Questions