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.
Related
I have a viewControllerA embedded in a navigationController.From this viewControllerA I want to navigate to another viewControllerB which is embedded in a tabBarController.
So I have a setup like -
viewControllerB is embedded in a navigationController and then this is embedded in tabBarController.
In viewControllerA I have a button from where I want to push to viewControllerB.
This is what I am trying to do -
-(void)areaBtnClicked:(id)sender{
NSLog(#"btn clicked");
UITabBarController *tbc = [self.storyboard instantiateViewControllerWithIdentifier:#"tabController"];
[self.navigationController pushViewController:tbc animated:YES];
}
However the app is crashing with a error message as -
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
Are you sured, that your controller has that identifier "tabController" ?
Check your storyboard.
Well apparently deleting the app from simulator solved the problem.
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'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.
In my app I need to manage a navigation controller and move it in these viewcontrollers, so I do it
UINavigationController *navController = (UINavigationController*) [self.storyboard instantiateViewControllerWithIdentifier:#"navigationcontroller"];
[navController addChildViewController:firstViewController];
[navController addChildViewController:secondViewController];
[navController addChildViewController:thirdViewController];
[navController addChildViewController:fourthViewController];
[self presentViewController:navController animated:YES completion:nil];
first problem: navigation open at first fourthviewcontroller, why?
second problem: if from secondviewcontroller i do it to pass at first:
[[self navigationController] pushViewController:self.navigationController.viewControllers[0] animated:NO];
I have a crash that say:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported
why? can you help me?
First question
Every time you use "addChildViewController:", the new controller is added at the top of the stack. The last one inserted, your fourthViewController, is at the top of the stack, so it is shown when you call the method
[self presentViewController:navController animated:YES completion:nil];
Second question
It depends on the pushViewController: method itself. In the Apple documentation the doc said that:
The viewController added cannot be an instance of tab bar controller and it must not already be on the navigation stack.
Your app crashes because self.navigationController.viewControllers[0] is already on navigation stack.
First Problem
You're pushing four view controllers onto the navigation stack. So, your stack, after each step, looks like this:
[navController addChildViewController:firstViewController];
Stack: firstViewController
[navController addChildViewController:secondViewController];
Stack: secondViewController, firstViewController
[navController addChildViewController:thirdViewController];
Stack: thirdViewController, secondViewController, firstViewController
You can see the pattern here. In other words, the fourthViewController is presented because it's on the top of the stack.
Second Problem
As for your second problem, you can't push a view controller onto the stack that already exists in the stack. [[self navigationController] pushViewController:self.navigationController.viewControllers[0] animated:NO]; seems absurd when you consider that fact. You're trying to push something from within the stack to the stack.
My iPad application has a SplitViewController, a MasterViewController and a DetailViewController. From the DetailViewController, I need to create a temporary view (managed with a PaletteViewController: UIViewController, and designed in a xib file) that the user can move on the screen to be able to see what content is backwards.
in DetailViewController.m:
#synthesize paletteViewController=_paletteViewController;
(...)
- (IBAction) loadPalette: (id) sender{
if (_paletteViewController == nil) {
self.paletteViewController = [[PaletteViewController alloc] init];
}
self.paletteViewController.delegate=self;
[self.paletteViewController setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentModalViewController:self.paletteViewController animated:YES];
(...)
I get an error message: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller .
Any idea?
I think you are in your paletteViewController and you are presenting modally paletteViewController over plaetteViewController . how is it possible.you can present paletteViewController over detailview or something(some paarent view).