Dismiss ViewController that is presented via Popup - ios

So i am creating an ipad recipe based app using storyboards. Just to give you an idea of the structure of my program here is the flow of View controllers:
ViewController --Modally--> PreviewViewController --Modally-->
RecipeViewController --Popup--> IngredientsViewController
All of this has been done in storyboarding. I created the IngredientsViewController and have linked it up to the RecipeViewController to be displayed as a popup, which works fine. However i want to be able to dismiss the IngredientsViewController programatically (because i've implemented voice command features). The problem is i can't seem to access the IngredientsViewController to dismiss it. (appologies i can't yet post any pictures).
I am using the following code to present the IngredientsViewController programatically (from within RecipeViewController):
[self performSegueWithIdentifier:#"ingr" sender:nil];
Which works fine to display the popup, but i cant dismiss it. I've tried to access it through the hierarchy of view controllers but cannot seem to find it, i would assume that it would be at the top of the stack, but apparently not? I've tried things like:
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
Again this was called from within RecipeViewController. But that simply dismisses the RecipeViewController and not the IngredientsViewController that is being presented by popup.
Just to be clear the IngredientsViewController is not a UIPopoverController, it is a normal viewController created in storyboard, and its segue style is popup linked to a button in the RecipeViewController.
Any help would be greatly appreciated. Thanks!

UIPopoverController *popOver = (UIPopoverController *)self.presentedViewController;
[popOver dismissPopoverAnimated:YES];
This should do the trick if your destination view controller is a UIPopoverController

Have you tried presentViewController:animated:completion: instead of performSegueWithIdentifier:?

Related

How to use Modal View Controllers correctly?

I have a tabbed Iphone project in which I am attempting to present one modal segue but from multiple different view controllers.
Essentially I want it to function the same way the stock music app works in IOS 9 for iphone. You can be in any one different tab and still be able to view the account page.
Demonstration
First problem/question.
How to mimic this behavior without making a ton of segues. Currently I have 3 separate views that I want to call a modal segue from but how can I achieve this without making duplicate segues
Second problem/question.
How to dismiss the modal view without it becoming a deprecated segue. I have found tuts on how to do this but they require another segue back to the "sender" view controller.
If only apple could provide some decent sample code to aid my efforts in my attempt to do this...
you can present and dissmiss any view controller object without segue like below,
UIViewController *vc = [[UIViewController alloc]init]; // your view controller here
// You can present VC like
[self presentViewController:vc animated:YES completion:^{
// do your task on completion
}];
// In your Presented VC you can dissmiss it like
[self dismissViewControllerAnimated:YES completion:^{
//do your task on completion
}];
Update as per comment :
You can instantiate story board like,
SideMenuViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"sideMenu"];
Here SideMenuViewController is custom viewController class set to viewcontroller from storyboard.
And make sure you have set storyboard Id under identity from identity inspector. Here my sideMenu is storyboard Identity!
So you can instantiate your storyboard viewcontroller like this and then present it as mentioned before
Hope this will help :)

Two Modal VC are displayed simultaneously ios

For some reason, when I try to open a view controller via modal segue, it opens up two of the same type. Why is this happening?
Warning: Attempt to present <ModalViewController: 0x7fa062c5edd0>
on <HomeViewController: 0x7fa062e16e40> which is already presenting
<ModalViewController: 0x7fa062fb9780>
This is causing problems because I try to use delegates, but my main view controller never gets the correct delegate.
The issue occurs when I click the the button which triggers showModalView
HomeViewController
- (IBAction)showModalView:(UIButton *)sender {
ModalViewController *modalView = [[ModalViewController alloc] init];
[self presentViewController:modalView animated:YES completion:nil];
}
I tried this solution here and here and a dozen other ones, but none seem to work for me.
Why is this happening?
The problem you're having, is because you've connected a segue to the button, and are also presenting the controller in code; you should be doing one or the other. When you removed the segue, you got a black screen because you're using alloc init to create your controller. If you made the controller in a storyboard, then you should use instantiateViewControllerWithIdentifier: instead.
However, the easier way would be to leave the segue connected to the button, and delete the code you have in the button's action method. The button doesn't need an action method, if you have it hooked directly to a segue. All of this is covered in Apple's document, "View Controller Programming Guide for iOS". You should read it.

Xcode - How to switch view in storyboard

I'm developing my first iPhone app. I'm still not very good at Xcode and my question is pretty simple. I'm using Xcode 5 and I'm using storyboards in my project.
Well, I have some images in a View Controller. I'd just like that if I tap one of those images I switch to another View Controller, nothing else. How do I exactly do that?
I looked for a solution online and I found out on YouTube that I have just to Control-Click my image and connect it to another view using a modal connection, without any code. However I tried in the simulator and it doesn't work. Also, most of tutorials online are outdated and they explain how to do it on Xcode 4.2 and without using storyboards.
Can you help me please? Thank you.
Try this:
HomeViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"Home"];
[self presentViewController:vc animated:YES completion:nil];
with Home is Storyboard ID of Home Screen
You can't just use a UIImage. You need to use a UIButton and then under the properties set the button to custom and set background image to the image you want. Then you can click and drag from the button to the new view and choose modal.
I'm having you choose modal because from what I can gather, you aren't using a navigation controller. Therefore you'd modally want to present the view controller.

Unresponsive view instantiated with instantiateViewControllerWithIdentifier:

Im having some trouble with a view that I needed instantiating from a storyboard ID. In IOS simulator, the view loads with everything in place but is completely unresponsive. The date picker doesn't move and the buttons don't accept any interaction.
Ive checked the 'custom class' matches in IB and the Storyboard ID matches. The code is being executed in the PickerViewController because the UIDatePicker is being created in code and is correct and present in IOS simulator. Its just that nothing accepts any interaction. The buttons don't even go blue when touched.
I created the view in the previous view controller with:
PickerViewController *addViewController = (PickerViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"view"];
[addViewController.view setUserInteractionEnabled:TRUE];//chucked this line in to see if it helped
[addViewController setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:addViewController animated:YES completion:NULL];
I'm not sure if this is a code problem, or if I've not hooked something up in IB properly. Any ideas??!!
Check your view controllers class in assistant editor:

presentViewController is disabling all removeFromSuperview messages in a UISplitViewController

Here is a visual representation of the UISplitViewController:
I'm trying to present a UIViewController (myVC) that's a subview of a UIView inside the DetailViewController of a UISplitViewController using this:
[appDelegate.splitViewController presentViewController:myVC animated:NO completion:nil];
It presents, I dismiss it, the app rotates without a hitch, then when I try to reload the detail view by clicking on a cell in the rootViewController (a UINavigationController), all the [orangeUIView removeFromSuperview] messages are mysteriously disabled (there are more orange UIViews hidden here that are inside a mainScrollView). The "INFO LABEL" in the topToolbar is updating, so I know the cell is sending data...
Why would this activity disable removeFromSuperview if presented using splitViewController? I've presented myVC using the detailViewController...
[appDelegate.detailViewController presentViewController:myVC animated:NO completion:nil];
which doesn't disable removeFromSuperview, but causes an assortment of other rotational crashes.
What's going on here?
Since this question was created as a result of a previous question, the answer to this problem was...try something else. I was unable to fix this problem by presenting a view controller, most likely because I'm using a custom UISplitViewController with a hierarchy I'd rather not get into.
Here is the solution I came up with:
Core Plot - Options on making the graph full screen - addSubview after presenting modal problems

Resources