I'm trying to pass parameter from one view controller to another, but application crashes with exception.
My code is this:
SelectedItemViewController *nextView = [storyboard instantiateViewControllerWithIdentifier:#"SelectedItemViewID"];
nextView.m_selectedItemId = [NSNumber numberWithInt:777];
[self presentViewController:nextView animated:YES completion:NULL];
And I have the following in my stack:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setM_selectedItemId:]: unrecognized selector sent to instance 0x9c765d0'
In your storyboard, the view controller with identifier SelectedItemViewID is a navigation controller, not a SelectedItemViewController. So, before you set m_selectedItemId you should access the navigation controllers root view controller (which should be your SelectedItemViewController).
I found solution here: instantiateViewControllerWithIdentifier and pass data
What should be done in case if you want to pass parameter to view controller via navigation controller:
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"SelectedItemViewID"];
SelectedItemViewController *nextView = navigationController.viewControllers[0];
nextView.m_selectedItemId = [NSNumber numberWithInt:777];
[self presentViewController:navigationController animated:YES completion:NULL];
When you select the view controller in your storyboard, is the class set to SelectedItemViewController?
Obviously you seem to have a #property ... m_selectedItemId (or at least setter method setM_selectedItemId) on SelectedItemViewController, otherwise your code wouldn't even compile. But it seems that [storyboard instantiateViewControllerWithIdentifier:#"SelectedItemViewID"] doesn't really return the expected SelectedItemViewController. Hence I have the feeling that you forgot to set the correct class name to SelectedItemViewController in your storyboard.
Related
i have Storyboard with UINavigationController i have created the first screen with searchbar
i have added second viewcontrol via IB to storyboard
how do i push the second viewcontroller to navigationcontroller ?
i have tried
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
ViewController *screen2 = [[ViewController alloc] initWithNibName:#"ViewController2" bundle:nil];
[self.navigationController pushViewController:screen2 animated:YES];
}
i have set Custom Class of second view controller to ViewController2
but when i run the app and click the search button in keyboard i get the following error
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'ViewController2''
The error you are getting is because Xcode cannot find the xib named ViewController2.
You may just call self.performSegueWithIdentifier(#"identifierToViewController")
But first make sure that your searchViewController is a child of an UINavigationController
Then make sure that the segue has a proper identifier:
First of all make sure that your second view controller class name is : ViewController2
After that in storyboard give your View Controller's class name and Storyboard Id as #"ViewController2", Please refer screen shot.
Actually you use wrong method to create instance of UIViewController as it is used when you use xib file.
Change your code like this :
ViewController2 *screen2 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController2"];
[self.navigationController pushViewController:screen2 animated:YES];
I have a UISplitViewController (is the rootViewController)
and a UIViewController, vc1.
I'm trying to present vc1 over my split view controller from the MasterViewController part:
vc1.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentViewController:vc1 animated:YES completion:nil];
this raises an exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Application tried to present modally an active
controller <MasterViewController: 0x8c5dd30>.'
...and crashes.
Tried this:
[self.splitViewController presentViewController:vc1 animated:YES completion:nil];
This raises an exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason:'Application tried to present modally an active
controller <UISplitViewController:0x8c7e3a0>.'
However, if i try it with the interface builder (segues), it works.
How do i present a view controller, modally (as pages sheet or form sheet), over a split view controller, programmatically?
You can tell the DetailView controller to show it. Something like this I suppose.
DetailVC *detailVC = [self.splitViewController.viewControllers objectAtIndex:1];
[detailVC presentViewController:vc1 animated:YES completion:nil];
I suppose the issue is that your master is presenting a detail view and that's why it can't present anything else, so you ask the detail view to do it for you.
Getting a weird error when attempting to do a "push" sequence on a UIViewController.
I have embeded two UINavigationControllers into a root UIViewController.
I am basically attempting to make it so when the > button is pressed it pushes to the "View Controller."
Any ideas why I am getting the following error?:
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
This is my storyboard:
http://cl.ly/image/3K0s3J1U1A3W
I am getting to the RecordViewController like so:
RecordViewController *record = [self.storyboard instantiateViewControllerWithIdentifier:#"RecordView"];
[self presentViewController:record animated:YES completion:nil];
If you want to push view controllers to a presented view controller, then your presented view controller must be a UINavigationController. In your case, give the leftmost navigation controller an identifier (i.e RecordNavigationController) and convert your code to:
UINavigationController *recordNavigationController = (UINavigationController*)[self.storyboard instantiateViewControllerWithIdentifier:#"RecordNavigationController"];
[self presentViewController:recordNavigationController animated:YES completion:nil];
I have 1 View Controller and 1 Tab Bar Controller with 2 Navegation Controller.
In my simple View I have one form and then when I click in button "Login" I want to load the first View in my Tab Bar Controller.
With this code works perfect:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
Inicial *telaInicial = [storyboard instantiateViewControllerWithIdentifier:#"tabBar"];
[self presentViewController:telaInicial animated:YES completion:nil];
But I want to send and value to this View "Inicial" and I put this:
telaInicial.email = email.text;
But I got this error message:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController setEmail:]: unrecognized selector sent to instance 0x9fdc8f0'
The object telaInicial that you think is an instance of Inicial is actually a UITabBarController therefore you cannot set the email property on it as it doesn't exist.
I think you want something like this...
UITabBarController *tabBarController = [self.storyboard instantiateViewControllerWithIdentifier:#"tabBar"];
UINavigationController *navController = tabBarController.viewControllers[0];
Inicial *telaInicial = navController.topViewController;
telaInicial.email = // blah
It means that there isn't a setEmail method for the telaInicial object. Is that an instance of a subclass you've written? If so, you might be getting the error because you haven't written a setEmail method for it or because you haven't declared the instance variable email as an #property, in which case the setter and getter methods for it would be synthesized automatically by XCode (prior to XCode 4.something, I think you need to synthesize your properties explicitly - after that version, they're automatic).
Try to write class, that will store your data.
You can access to it from AppDelegate (not really good solution, but very fast).
I'm new in iphone, I'm trying to open a view when pressing a button,
in my class "ReaderViewController" I wrote the following code:
- (void)tappedInToolbar:(ReaderMainToolbar *)toolbar emailButton:(UIButton *)button
{
#ifdef DEBUGX
NSLog(#"%s", __FUNCTION__);
#endif
#if (READER_ENABLE_MAIL == TRUE) // Option
instantiateViewControllerWithIdentifier:#"searchView"];
if (printInteraction != nil) [printInteraction dismissAnimated:NO]; // Dismiss
SearchViewController *searchController = [self.storyboard instantiateViewControllerWithIdentifier:#"searchView"];
searchController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
searchController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:searchController animated:YES];
[searchController release];
#endif // end of READER_ENABLE_MAIL Option
}
I want when to open the view of this controller "SearchViewController" and in storyboard I gave the view of SearchViewController its identifier name "searchView"
but when I run, it gives me the following Exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <ReaderViewController: 0x6864930>.'
Any Help ??
Thanks in advanced.
There's no view controller with the identifier searchView in your storyboard, so the instantiation fails and the
instantiateViewControllerWithIdentifier:
method returns nil. Double check your Storyboard setup and also note that identifiers and names are generally case-sensitive, maybe you named your view controller SearchView and not searchView.
It also may be the case that
self.storyboard
itself isn't properly initialized or instantiated, and thus is nil.
Edit: so you were creating the storyboard from code, but in fact you weren't. The solution was to manually instantiate UIStoryboard.
As for your own comment, you'd better assign self.storyboard = Storyboard or you'll continue getting these errors...
It looks to me like self.storyboard is nil. This means every message you are passing to it results in nil also.