"Unrecognized selector sent to instance" after casting rootViewController to UINavigationController * - ios

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

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]);

Related

'NSInvalidArgumentException' on UILocalNotifcation Load

When loading my application from a local notification I am trying to read its payload. To do so I have the following code:
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Loading Stuff
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
[(UITabBarController *)self.window.rootViewController setSelectedIndex:1];
UINavigationController *nav = [[(UITabBarController *)self.window.rootViewController viewControllers] objectAtIndex:1];
IMTRewardsViewController *rvc = [storyboard instantiateViewControllerWithIdentifier:#"rewardsView"];
[rvc loadPushNotification:localNotif];
[nav pushViewController:rvc animated:NO];
}
return YES;
}
IMTRewardsController.h:
-(NSDictionary *)loadPushNotification:(UILocalNotification *)notification;
IMTRewardsController.m:
- (NSDictionary *)loadPushNotification:(UILocalNotification *)notification
{
NSLog(#"%#",notification.userInfo);
return notification.userInfo;
}
When I load my application from a local notification I receive the following error:
<Error>: -[UIViewController loadPushNotification]: unrecognized selector sent to instance 0x14e70b30
<Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController loadPushNotification]: unrecognized selector sent to instance 0x14e70b30'
Any idea as to how to fix this issue and keep it from cropping up in the future?
There error indicates the view controller you've pulled back is only a UIViewController, and not a IMTRewardsViewController like you're expecting. Are you sure you set the custom class property to that type in the storyboard?
You might need to cast it first. The storyboard returns an UIViewController
IMTRewardsViewController *rvc = (IMTRewardsViewController *)[storyboard instantiateViewControllerWithIdentifier:#"rewardsView"];

Core data and Master-Detail template, getting runtime exception.

I am trying to modify Master Detail project template generated by xcode.
But getting following problem:
2013-08-03 20:08:59.749 StudentsAtWork[20236:a0b] Unknown class cblMasterViewController in Interface Builder file.
2013-08-03 20:08:59.900 StudentsAtWork[20236:a0b] -[UITableViewController setManagedObjectContext:]: unrecognized selector sent to instance 0x8ec8120
2013-08-03 20:08:59.904 StudentsAtWork[20236:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewController setManagedObjectContext:]: unrecognized selector sent to instance 0x8ec8120'
*** First throw call stack:
(0x1a009b8 0x17818b6 0x1a9cc13 0x19f0cfb 0x19f08de 0x61ee 0x57bea9 0x57c6e9 0x57db5e 0x593a6c 0x593fd9 0x57f7d5 0x38ce906 0x38ce411 0x197c3e5 0x197c11b 0x19a6b30 0x19a610d 0x19a5f3b 0x57d2b1 0x57f4eb 0x6d7d 0x2060725)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
What I did basically, removed the generated master and detail view controller class and created my own MasterViewController class like following:
header file:
#import <UIKit/UIKit.h>
#interface cblMasterViewController : UITableViewController
#property (nonatomic,strong) NSManagedObjectContext* managedObjectContext;
#end
Implementation file:
#import "cblMasterViewController.h"
#interface cblMasterViewController ()
#end
#implementation cblMasterViewController
#synthesize managedObjectContext;
....
....
#end
and my app delegate code is as follows:
#import "cblAppDelegate.h"
#import "cblMasterViewController.h"
#implementation cblAppDelegate
#synthesize managedObjectContext = _managedObjectContext;
#synthesize managedObjectModel = _managedObjectModel;
#synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
UINavigationController *masterNavigationController = splitViewController.viewControllers[0];
cblMasterViewController *controller = (cblMasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
} else {
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
cblMasterViewController *controller = (cblMasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
//}
return YES;
}
Also I have deleted detail view from my storyboard.
I am new in using storyboard. So I am not sure what is going wrong here.
Can anyone give me some clue?
Thanks.

Crash switching views when adding data to a property

When trying to switch views (minus the two lines that add data to a property, it works fine. However with the 2 lines in (which is these two):
self.firstViewData = fvc;
firstViewData.passedData = #"hello test test test";
It crashes saying:
2013-05-29 16:40:43.864 test [16166:907] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController setPassedData:]: unrecognized selector sent to instance 0x325620'*
Whole segment:
FilterViewController.h
#interface FilterViewController : UIViewController
{
FirstViewController *firstViewData;
}
#property (nonatomic, retain) FirstViewController *firstViewData;
FilterViewController.m
#synthesize firstViewData;
- (IBAction)backToMap:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
FirstViewController *fvc = [storyboard instantiateViewControllerWithIdentifier:#"TabBarController"];
fvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
self.firstViewData = fvc;
firstViewData.passedData = #"hello test test test";
[self presentViewController:fvc animated:YES completion:nil];
}
FirstViewController.h
#interface FirstViewController : UIViewController
{
NSString *passedData;
}
#property(nonatomic, retain) NSString *passedData;
FirstViewController.m
#synthesize passedData;
NSLog(#"result: %#", passedData);
Your fvc variable is a UITabBarController, not a FirstViewController. Look into how you set fvc.

NSInternalInconsistencyException error

I am having issues switching between view controllers.
My md360AppDelegate.h header looks like this
#import <UIKit/UIKit.h>
#class md360ViewController;
#interface md360AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) md360ViewController *viewController;
#property (strong, nonatomic) UINavigationController *navigationController;
#end
and my md360AppDelegate.m implementation looks like this.
#import "md360AppDelegate.h"
#import "md360ViewController.h"
#implementation md360AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[md360ViewController alloc] initWithNibName:#"md360ViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.window setRootViewController:self.navigationController];
[self.window makeKeyAndVisible];
return YES;
}
#end
i am creating an instance of UINavigationController and storing it in navigationController property of this class.
I want to change the ViewController when a user click on a button in md360ViewController.
My md360ViewController.h looks like this.
#interface md360ViewController : UIViewController
#property IBOutlet UIButton *homePathwayBtn;
#property IBOutlet UIButton *homeDiseaseBtn;
#property IBOutlet UIButton *homePipelineBtn;
- (IBAction)homeButton:(id)sender;
#end
and my implementation looks something like
#import "md360ViewController.h"
#import "md360AppDelegate.h"
#import "pipeViewDisease.h"
#import <QuartzCore/QuartzCore.h>
- (IBAction)homeButton:(id)sender {
UIViewController *pipeViewDisease = [[UIViewController alloc] initWithNibName:#"pipeViewDiease" bundle:nil];
[self.navigationController pushViewController:pipeViewDisease animated:YES];
}
and when i click on UIButton the application crash with following message.
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Could not load NIB in
bundle: 'NSBundle
(loaded)' with name 'pipeViewDiease''
what could be the issue?
Probably just a misspelled NIB name:
initWithNibName:#"pipeViewDiease"
should be:
initWithNibName:#"pipeViewDisease"
^
Unless it's a spelling mistake (should be pipeViewDisease), this error usually occurs when files are re-named outside of the xCode environment.
To fix this:
remove the file in question from the project
re-import the files to your project.

this class is not key value coding-compliant for the key view.'

I have a problem in AppDelegate, when run the app I get this error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<UIApplication 0x856c820> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key view.'
This is the code of AppDelegate.h
#import <UIKit/UIKit.h>
#class ViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>{
//UINavigationController *navigationController;
}
#property (strong, nonatomic) UIWindow *window;
#property (copy, nonatomic) ViewController * viewController;
#property (copy, nonatomic) UINavigationController * navigationController;
#end
This is the code of AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *rootMenu;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
rootMenu= [[RootViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
} else {
rootMenu = [[RootViewController alloc]initWithNibName:#"ViewController_iPad" bundle:nil];
}
self.navigationController =[[UINavigationController alloc]initWithRootViewController:rootMenu];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
What can I do to resolve this error? I have rewritten the RootViewController, throwing in the trash the old one, but the problem remains the same.Thanks in advance
This usually happens when an Interface Builder or Storyboard connection hasn't properly been made. Sometimes you'll make a connection, and then delete the code that the connection was made to. Interface Builder still has a reference to the code, which causes the key/value compliant run time error. You can also get this error if you haven't assigned the proper class to a view controller. If you've written code for a particular view controller, be sure to set the class appropriately in Interface Builder for that View Controller.
I know this question is a bit old, but I was running into the same problem and the article below helped a lot. Basically it illustrates step-by-step how to fix the problem #bgolson described.
http://www.tech-recipes.com/rx/52021/how-do-i-fix-the-issue-this-class-is-not-key-value-coding-compliant-for-the-key-in-xcode-6/

Resources