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.
Related
I don't know how to solve this problem:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController pushViewController:animated:]: unrecognized selector sent to instance 0x8e5fc70'
This problem is connected to screen timeout. After 30 seconds of no activity, my App have to back to the login screen, and if the user come back he have to login again. And this is my code:
AppDelegate.h:
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
AppDelegate.m:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(applicationDidTimeout:) name:kApplicationDidTimeoutNotification object:nil];
return YES;
}
-(void)applicationDidTimeout:(NSNotification *) notif
{
NSLog (#"time exceeded!!");
UIViewController *controller = [[UIStoryboard storyboardWithName:#"Main" bundle:NULL] instantiateViewControllerWithIdentifier:#"mainView"];
[(UINavigationController *)self.window.rootViewController pushViewController:controller animated:YES];
As you can see the problem is in the last line of this code. This part of the code which I used has been taken from:
iOS perform action after period of inactivity (no user interaction)
The pushViewController:animated: method is a method of UINavigationController.
But your root view controller is of type ViewController which is most likely a UIViewController.
You need to change your setup so your main view controller is inside a UINavigationController and you need to make the navigation controller the window's root view controller.
This means in storyboard the rootViewController is a navigationController
I want to pass data from Master view controller to Detail view controller according to the picture below. I am using protocols and Delegates to pass data. There is no problem to pass data from A to B. It happens when I try to pass data from A to C.
But the app is returning the error:
014-07-05 01:03:00.043 PassingDataBack[2216:70b] -[UIViewController
didSelectData:]: unrecognized selector sent to instance 0x8e3d2d0
2014-07-05 01:03:00.047 PassingDataBack[2216:70b] *** Terminating app
due to uncaught exception 'NSInvalidArgumentException', reason:
'-[UIViewController didSelectData:]: unrecognized selector sent to
instance 0x8e3d2d0'
I believe the problem is in the AppDelegate file that i wrote:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UISplitViewController *splitViewController = (UISplitViewController *) self.window.rootViewController;
splitViewController.delegate = [splitViewController.viewControllers lastObject];
DetailViewController *detailViewController = (DetailViewController *)[[splitViewController.viewControllers objectAtIndex:1] topViewController];
MasterViewController *masterViewController = (MasterViewController *)[[splitViewController.viewControllers objectAtIndex:0] topViewController];
masterViewController.delegate = detailViewController;
// Override point for customization after application launch.
return YES;
}
Could you help to find the solution?
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.
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]);
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/