I have a universal app but this issue seems to only relate to the iPad and not the iPhone since the iPhone version loads the correct XIB.
So pretty much the issue is, it is not loading my main XIB for my app. I named the XIB's like so:
For iPhone: MyViewController.xib
For iPad: MyViewController_iPad.xib
Also I deleted my MainWindow.xib because in the template project for a universal app it shows no MainWindow.xib anywhere.
This is how I am trying to load the view on app launch:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[ocrapiViewController alloc] initWithNibName:#"MyViewController" bundle:nil] autorelease];
} else {
self.viewController = [[[ocrapiViewController alloc] initWithNibName:#"MyViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
This is the crash info:
A SIGABRT on this line [self.window makeKeyAndVisible];
And this is the crash log:
2011-12-07 07:37:46.560 ocrapi[763:607] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/29F4CD7A-149E-46EA-B280-3D188PP19D17/.app> (loaded)' with name 'MyViewController_iPad''
Edit1:
Here is the message:
warning: No copy of <No file name> found locally, reading from memory on remote device. This may slow down the debug session.
Also if I click on my products then do show in finder, then do show package contents, MyViewController.xib or MyViewController_iPad.xib is not there. Is it supposed to be like that?
Make sure your nib really really really is called MyViewController_iPad.xib, with that exact capitalization.
Make sure the xib file is in your target's list of things to be copied to the app on build.
Finally, make sure you've no Main Nib setting still in your Info.plist file.
Oh, and one more thing. There is no need for this code:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[ocrapiViewController alloc] initWithNibName:#"MyViewController" bundle:nil] autorelease];
} else {
self.viewController = [[[ocrapiViewController alloc] initWithNibName:#"MyViewController_iPad" bundle:nil] autorelease];
}
Simply call initWithNibName:#"MyViewController". If your iPad nib is named MyViewController~ipad.xib (note the twiddle, note the lowercase "ipad") it will be chosen automatically when you're on an iPad.
Related
I'm trying to get Xcode's iphone simulator to display by nib after the launch screen, but I keep getting this error.
Full error:
2015-03-26 21:01:40.462 Hangman Jury[5278:476697] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'HangController''
Relevant code:
in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[HangController alloc] initWithNibName:#"HangController" bundle:nil];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Erroring line in main.m:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
HangController is a simple subclass of UIViewController
Things I've tried:
-Spelling "HangController" correctly
-Making sure View2.xib is included in Copy Bundle Resources
-I have not renamed anything outside of Xcode
-I'm not using storyboards and I have removed storyboard items from Info.plist
-My view is linked to the target in the Target Membership list
Thanks for your help
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0xa46e6a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
I've been researching this for the past couple of days but I haven't found an answer that gets my app to run.
I have a universal app with two nib files (one for phone, one for pad) and no matter what I change I keep running into this runtime error. I have triple-checked my connections in the Interface Builder. I also defined the main interfaces for both phone and pad respectively.
This is what my AppDelegate.m looks like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
ViewController *viewController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
}else {
viewController = [[ViewController alloc] initWithNibName:#"ViewController-iPad" bundle:nil];
}
self.window.rootViewController = viewController;
[viewController release];
[self.window makeKeyAndVisible];
return YES;
}
I would like to suggest to check your xib files of ViewController.
Is the custom class of file's owner set to ViewController?
and view outlet connected to file's owner?
and then try it again.
First of all, I'm a beginner, so I might have my concepts wrong.
This is my code in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *viewController = [[UIViewController alloc] initWithNibName:#"FirstView" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController: viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
The idea is to programmatically add UINavigationController, but then use a .xib (the "FirstView" paremeter) for the views. I have no problem with programmatically creating the views as well, but for simpler interfaces, I assume using IB can be done as well.
However, when I run the code, I get this error:
2013-07-11 21:20:42.644 new-book-proto-01[64308:11303] *** Terminating app due
to uncaught exception 'NSInternalInconsistencyException', reason:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstView" nib
but the view outlet was not set.'
What should I do? Is there anything missing?
Additionally, is something like this common in iOS development? Is it bad practice? Is there a better way to do this?
This is the reason as told: "reason:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstView" nib
but the view outlet was not set.' "
It means that you try to access or get value for some views (UI elements) that has not IBOutlet in your controller class or you have none view at all
You should create IBOutlets (properties) for each view (each UI element is view) that you would like to "see" in your controller
I am writing an iOS app; no ARC and no storyboards.
I have a view controller inside Navigation controller. It supposed to have Table view and navigation button which pushes to second view.
This is the error I get:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ViewController" nib but the view outlet was not set.'
*** First throw call stack:
(0x1c8d012 0x10cae7e 0x1c8cdeb 0xf2f18 0xf3418 0xf3648 0xf3882 0x42a25 0x42dbf 0x42f55 0x4bf67 0x2a88 0xf7b7 0xfda7 0x10fab 0x22315 0x2324b 0x14cf8 0x1be8df9 0x1be8ad0 0x1c02bf5 0x1c02962 0x1c33bb6 0x1c32f44 0x1c32e1b 0x107da 0x1265c 0x2442 0x2375)
libc++abi.dylib: terminate called throwing an exception
(lldb)
The code in AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewCon = [[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
self.navCon = [[UINavigationController alloc]initWithRootViewController:self.viewCon];
self.navCon.navigationBar.tintColor= [UIColor greenColor];
self.viewCon.title= #"First View";
self.tblView = [[UITableView alloc] init];
NSMutableArray *viewArr=[[NSMutableArray alloc] init];
[viewArr addObject:self.navCon];
self.navBar = [[UINavigationBar alloc] init];
self.viewCon.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Second View" style:UIBarButtonSystemItemAdd target:self action:(nil)];
[self.window addSubview:self.navBar];
self.window.rootViewController = self.viewCon;
[self.window makeKeyAndVisible];
return YES;
}
At this stage I cannot run even the app. What might be the prob?
Best regards
loaded the "ViewController" nib but the view outlet was not set.
It seems you forgot to connect the view outlet of the view controller to your actual view in ViewController.xib file.
Your xib file has got a file's owner. This you have presumably set to be a ViewController (which I imagine is a subclass of UIViewController).
Now, if you go to the right-hand pane and show the bindings pane (the last one, with a small arrow), you will see that the view controller has got an outlet called view: drag from the small circle on its right on to the view which you have created in the xib.
I am getting started with iOS programming, and created a new project in XCode 4.2.1. However, I do not see .xib file in my project as expected. I tried added a new .xib file and build interface on it, but when I run my program, I see a blank white screen on the iPad Simulator. Am I missing something? Thanks.
You can replace this method in the appDelegate (and the name of the xib / strip out universal aspects of code if needed)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
} else {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
or
choose a Single View Application from the templates you are offered when creating a new app