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
Related
This is my Storyboards :
Say I have a Sign In viewController above these and from where I want to make SWRevealViewController as my rootViewController, so that It can work perfectly. With the below code, From my leftMenuViewController I can select my tabBar with desired ViewController perfectly.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITabBarController *tabBarController = (UITabBarController *)self.revealViewController.frontViewController;
UINavigationController *navController = tabBarController.viewControllers[indexPath.row];
[navController popToRootViewControllerAnimated:NO];
tabBarController.selectedIndex = indexPath.row;
self.revealViewController.rearViewRevealOverdraw = 0.0f;
[self.revealViewController pushFrontViewController:tabBarController animated:YES];
}
But it is not working in App delegate or in SignInViewController.
- (void)checkIfUserSignedIn
{
if ([ManagerClass getBOOLTypeUserDefaultForKey:#"isSignedIn"] == YES) {
UITabBarController *tabBarController = (UITabBarController *)self.revealViewController.frontViewController;
UINavigationController *navController = tabBarController.viewControllers[0];
[navController popToRootViewControllerAnimated:NO];
tabBarController.selectedIndex = 0;
self.revealViewController.rearViewRevealOverdraw = 0.0f;
[self.revealViewController pushFrontViewController:tabBarController animated:YES];
self.window.rootViewController = tabBarController;
} else {
}
}
It is giving this in log:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'
Any help will be highly appreciated. Thanks a lot in advance.
Have a good day.
All I need to do is this:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:mainStoryboard bundle:[NSBundle mainBundle]];
SWRevealViewController *controller = (SWRevealViewController *)[storyBoard instantiateViewControllerWithIdentifier:#"RevealViewControllerID"];
[self.window setRootViewController:controller];
Just set SWRevealViewController as your rootViewController of the project. :)
your answer above is right but the crash you mentioned in you question
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'
was caused from you storyboard because the SWRevealVC in the image you posted above is not set to initial view controller, select your view controller then from Attribute Inspector check the option available Is Initial View Controller like
you should see an Arrow pointing from you SWRevealVC
What I Want?
In MainViewController I open a view from a xib programmatically. This
xib view contains a UIButton. The xib opens successfully.
On click of that UIButton I want to move FeedBackViewController
My code
This is the code I am using to move FeedBackViewController on click of the UIButton
FeedBackViewController *view=[self.storyboad instantiateViewControllerWithIdentifier:#"FeedBackView"];
[self presentViewController:view animated:YES completion:nil];
But it is crashing and I am receiving the following message:
Terminating app due to uncaught exception 'NSInvalidARgumentException', reason: 'Application tried to present a nil modal view controller on target FutureOrderViewController: 0x199a4a30.
Check these things
Check the identifier of the viewcontroller, if it is the same that you mentioned in storyboard
Make sure that your view object is not nil. Set a breakpoint on that line and on the debug area at the bottom see whether the object is not nil. If it is nil then problem lies in the storyboard connection
If your current viewcontroller is not launched from storyboard then get storyboard object like this :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * feedbackVC = [storyboard instantiateViewControllerWithIdentifier:#"FeedBackView"] ;
[self presentViewController:feedbackVC animated:YES completion:nil];
whenever you want to load a VC as the way you mentioned, you need two things.
Thing 1: Specific storyboard ID. you will find this by:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Your_Storyboard_Id" bundle:nil];
In my case this is Main
Thing 2:
You need your View Controller id. Just click on the View Controller you want to go from storyboard and give a suitableName there.
Then invoke this like:
UIViewController * yourVC = [storyboard
instantiateViewControllerWithIdentifier:#"YourVC_ID"] ;
And if you want to present it modally you already did this. :)
[self presentViewController:yourVC animated:YES completion:nil];
Try this
UIStoryboard *story = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
FeedBackViewController * feedbackVC = [story instantiateViewControllerWithIdentifier:#"FeedBackView"] ;
[self presentViewController:feedbackVC animated:YES completion:nil];
Where FeedBackView is your storyboard id of FeedBackViewController.
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
-(void)btnclick1:(UIButton *)sender
{
NSString *storyboardName=#"Main";
UIStoryboard* storyboard1 = [UIStoryboard storyboardWithName:storyboardName
bundle:nil];
secondViewController *add = [[secondViewController alloc]init];
add =[storyboard1 instantiateViewControllerWithIdentifier:#"nextseg"];
[self.view addSubview:add.view];
[self presentViewController:add
animated:YES
completion:nil];
}
I got error: reason: 'Storyboard () doesn't contain a view controller with identifier 'nextseg''
You need to set the Storyboard ID for the xib you want to use in the MainStoryboard Settings for the XIB, see image. In your case it should be #"nextseg"
Hope this helps.
Cheers.
Just add [NSBundle mainBundle] to the bundle argument where you get the storyboard from. Hope this helps
-(void)btnclick1:(UIButton *)sender
{
NSString *storyboardName=#"Main";
UIStoryboard* storyboard1 = [UIStoryboard storyboardWithName:storyboardName
bundle:[NSBundle mainBundle]];
secondViewController *add = [[secondViewController alloc]init];
add =[storyboard1 instantiateViewControllerWithIdentifier:#"nextseg"];
[self.view addSubview:add.view];
[self presentViewController:add
animated:YES
completion:nil];
}
Also make sure you have a identifier "nextseg" for your view controller. "nextseg" should not be the identifier of the segue leading to the view controller, but it should be for the view controller
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];