Why couldn't xcode load my NIB - ios

When running a program in XCode I received the following error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/user/Library/Developer/CoreSimulator/Devices/646F9805-AC4E-40A8-BC62-75B92339DCDC/data/Containers/Bundle/Application/D6C27367-F61B-4CAC-BB9E-1D48227CE629/WhatsNap.app> (loaded)' with name 'DisplayWarningViewController''
I am running the following lines of code and it gets an exception at the last line. I'm not sure as to why it happens. Other answers on this subject on SO indicate that the nib file might not be connected?
DisplayWarningViewController* DWVC = [[DisplayWarningViewController alloc]initWithNibName:#"DisplayWarningViewController" bundle:nil];
DWVC.delegate = self;
[self presentViewController:DWVC animated:NO completion:nil];

Looks like you have view controller defined in storyboard! In that case you should do
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
DisplayWarningViewController *displayWarningVC = (DisplayWarningViewController *)[storyboard instantiateViewControllerWithIdentifier:#"DisplayWarningViewController"]

Related

exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: ...can someone please find what is wrong with this

error occurs with below code---Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'Could not load
NIB in bundle:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *dvc =[[DetailViewController alloc]initWithNibName:#"DetailViewController" bundle:nil];
dvc.index = indexPath.row;
[self.navigationController pushViewController:dvc animated:YES];
}
As mentioned in your comments you are using Storyboard, then this is not how you will initialize an object of UIViewController with the storyboard.
You must create object like this
DetailViewController *vcDetailViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"DetailViewController"];
vcDetailViewController.index = indexPath.row;
[self.navigationController pushViewController:vcDetailViewController animated:YES];
Also, you need to give StoryBoard Id to your view controller, check image

Using Storyboard instead of Nib

I'm trying to recreate a small iOS app that utilized nib files. I'm trying to replace the following line of code
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
with:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController* viewController = [sb instantiateViewControllerWithIdentifier:#"viewController"]; self.window.rootViewController = self. viewController;
I'm getting the following error: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'viewController''
I got the latter code from a previous Stack Overflow question on a similar topic. Can someone please advise on what the issue I'm having is and how to proceed?
You need to name the view controller in your storyboard by giving it a storyboard id. I typically try to use something memorable like the name of the view controllers class so I don't have to look it up.

performSegueWithIdentifier NSInvalidArgumentException after call from AppDelegate

Hey together,
I am calling a void with some parameters from the AppDelegate on my main view.
This is done if a push notification is received:
MainViewController *mainView = [[MainViewController alloc] init];
[mainView showPushView:pushDataObject];
The called void # the MainView doing some data operating stuff and after that it should load the pushView:
- (void)showPushView: (PFObject *)pushDataObject {
NSLog(#"Push Data object transfered %#", pushDataObject);
pushItem = pushDataObject;
//All working fine to this point
[self performSegueWithIdentifier:#"showPushObject" sender:self];
}
Now the problem is that the app is crashing at [self performSegueWithIdentifier:#"showPushObject" sender:self]; with this Error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Receiver (<MainViewController: 0x145b80e0>) has no segue with identifier 'showPushObject''
*** First throw call stack:
(0x2e51fe83 0x3887c6c7 0x30f656d9 0xbeb11 0xb2a23 0x1745f7 0x38d610c3 0x38d610af 0x38d639a9 0x2e4ea5b1 0x2e4e8e7d 0x2e453471 0x2e453253 0x3318d2eb 0x30d08845 0xafecd 0x38d75ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
I think that there is a problem because I call the void from the AppDelegate, am I right?
Those anyone know a fix for that problem?
Thanks a lot!
Best regards from Germany :)
P.S. If I call [self performSegueWithIdentifier:#"showPushObject" sender:self]; with a button or something on the MainViewController all working fine... :/
In order for the segue to work, you need to have the storyboard loaded in the mainView when you start it that way. Try instead something like this:
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *firstViewController = [storyboard instantiateViewControllerWithIdentifier:#"kYourMainViewControllerIdentifier"];
self.window.rootViewController = firstViewController;
[self.window makeKeyAndVisible];
Remember to give an identifier to your root view controller and change it in this piece of code.
Your problem is this line:
MainViewController *mainView = [[MainViewController alloc] init];
because it means that the mainView instance doesn't have a storyboard (so it can't have any segues).
When you run it from a button the controller instance must have been created from a storyboard.
So, to fix, load the storyboard and instantiate mainView from it. Then the segue will work.
UIStoryboard *storyboard4Inch = [UIStoryboard storyboardWithName:#"Storyboard4Inch" bundle:nil];
UIViewController *mainViewController = [storyboard4Inch instantiateViewControllerWithIdentifier:#"MainViewController"];
[mainViewController showPushView:pushDataObject];

UINavigationController , pushViewController Error

I have 2 view controller
VC1 has button
in this button action
- (IBAction)clickSearch:(id)sender
{
NSArray *vc=[self.navigationController viewControllers];
ViewControllerSearch *vcSearch=nil;
for (int i=0; i<[vc count]; i++)
{
UIViewController *tempVC=[vc objectAtIndex:i];
if([tempVC isKindOfClass:[ViewControllerSearch class]])
{
vcSearch=[vc objectAtIndex:i];
break;
}
}
if(vcSearch)
{
[self.navigationController popToViewController:vcSearch animated:YES];
}
else
{
ViewControllerSearch *vc3New= [[ViewControllerSearch alloc]initWithNibName:#"ViewControllerSearch" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:vc3New animated:YES];
vc3New = nil;
}
}
ViewControllerSearch id my second view controller.these two view s connected with push segue.
when i click the button coming this error.
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Could not load NIB in bundle: 'NSBundle </Users/Ravi/Library/Application Support/iPhone Simulator/6.0/Applications/42268111-F290-40B8-B893-4649852F762C/coffee break app.app> (loaded)' with name 'ViewControllerSearch''
how can i fixed this error?please give me idea.
Are you certain your Nib is called 'ViewControllerSearch.xib'?
Also you don't need to nil out vc3New - in fact you probably shouldn't.
UPDATED
...to load from a storyboard, as mentioned in the comment, you need to do something like this:
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
ViewControllerSearch* controller = [storyBoard instantiateViewControllerWithIdentifier:#"ViewControllerSearch"];
1) Make to sure the storyboard identifier matches what you've named it
2) Make sure you've set/used the correct identifier, in the storyboard, for your controller

Could not find a storyboard

I have a project that uses nib files, no storyboards. Depending on the app settings I need to display a different screen than what is being displayed now when the app is launched. I created this view as a storyboard in Interface Builder. In the main view controller's viewWilllAppear methodwhen certain conditions are true, I am trying to load the new storyboard and view controller:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"IncompleteSettings.storyboard" bundle: [NSBundle bundleWithIdentifier:#"Convention"]];
IncompleteSetingsViewController *vc = [storyboard instantiateInitialViewController];
I have tried passing nil and [NSBundle mainBundle] to the bundle argument.
I get this error:
08-09 11:38:39.188 Convention[17091:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'IncompleteSettings.storyboard' in bundle NSBundle (loaded)'
Project Details:
You shouldn't add the extension in the name of the storyboard:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"IncompleteSettings" bundle:nil];

Resources