I present modal view which is a navigation controller:
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:photoEditVC];
[self presentViewController:nvc animated:YES completion:NULL];
Once I'm done with the modal view, inside nvc's visible controller:
[self.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
Result
Any ideas why this could happen?
UPDATE:
I realized this only happens when before dismissing the view, I update a value in a shared singleton class, I use to keep track of events.
[[SAStatus current] setValue:#(ua_photoSubmitted) forKeyPath:#"actions.user"];
[self dismissViewControllerAnimated:YES completion:NULL];
But it works fine if I do this:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[[SAStatus current] setValue:#(ua_photoSubmitted) forKeyPath:#"actions.user"];
}];
or I can do this and it also works fine:
[self dismissViewControllerAnimated:YES completion:^{
[[SAStatus current] setValue:#(ua_photoSubmitted) forKeyPath:#"actions.user"];
}];
At the time, no other classes observer that variable so I do not understand why it would affect the modal view.
Not sure that this is causing the black screen, but the presented view controller should call dismissViewController on itself, not on the presenting view controller.
[self dismissViewControllerAnimated:YES completion:nil];
I saw this issue with iOS 8 GM. Dismissing with animated set to NO did the trick.
Related
I have just started working on ios.
I created a Modalviewcontroller (VC1) and presented another modalViewcontroller (VC2).
There is a button (dismiss) on VC2 which will have to dismiss both viewcontrollers.
The way i know is call :-
[self dismissViewControllerAnimated:YES completion:nil];
in VC2
then call the same in VC1
So i created a delegate which tells me if dismiss is clicked in VC2.
so when dismiss is clicked:-
i call
[self dismissViewControllerAnimated:YES completion:nil];
in VC2
then that delegate method takes me to VC1
where I again call
[self dismissViewControllerAnimated:YES completion:nil];
This method was perfectly working till i was using the app in ios9
when i shifted to ios7 i started getting the warning and VC1 was not getting dismissed.
Please let me know why is this happening.
So the part which works for me as told in comments.
[self.presentedViewController dismissViewControllerAnimated:YES completion:^{
[self dismissViewControllerAnimated:YES completion:nil];
}];
So, error tells you exactly what happened. You trying to dismiss VC1, while your VC2 dismissing. By putting dismissViewControllerAnimated into delegate method does not guarantee that VC1 will be dismissed before, instead of that you should call your [self dismissViewControllerAnimated:YES completion:nil]; in completion block after first dismiss, so your code will look like that:
[self dismissViewControllerAnimated:YES
completion:^{
[self dismissViewControllerAnimated:YES completion:nil];
}];
I am loading a ViewController from a Storyboard like this:
SSContentViewController* contentViewController =
[[UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil]
instantiateViewControllerWithIdentifier:#"settingsViewController"];
and add it to my ViewController Array:
[self.viewControllers addObject:contentViewController];
inside the SettingsViewController I have a segue with presents a modal view controller. If I perform this segue I get a "Presenting view controllers on detached view controllers is discouraged"-Warning in the console output.
But there is nothing wrong with it. Everything is working as expected. Is it safe to ignore this warning?
EDIT:
The problem is that the ViewController on which I perform the segue is added to my RootViewController with:
[rootVC.view addSubview:viewController.view];
So I know that it is detached. But even with that warning things are working as they should and do not produce visual errors, etc...
you should actually use presentViewcontroller and dismissviewcontroller to avoid this.
Instead of adding use:
[self.view.window.rootViewController presentViewController:contentViewController animated:YES completion:nil];
And from model view use below to dismiss:
[self dismissViewControllerAnimated:YES completion:nil];
Edit 01:
for frame rate drop try below:
[picker dismissViewControllerAnimated: YES completion:^{
[self performSelector:#selector(reinit) withObject:nil afterDelay:2];
}];
I have been developing an iPhone app and have come across a few issues. I do not have a storyboard in my app and have nothing in my xibs. I have initialised and set everything up through code. When I go to the GameViewController from my main viewcontroller everything is fine, however when I come back through my back button I get this issue:
Presenting view controllers on detached view controllers is discouraged .
When I re-arrive to the main view controller, there are little changes such as the view changing before its supposed to. Here is the code for the button on my
GameViewController *game = [[GameViewController alloc] initWithNibName:nil bundle:Nil];
[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:game animated:YES completion:NULL];
Here is the code for the back button:
ViewController *home = [[ViewController alloc] initWithNibName:nil bundle:nil];
[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:home animated:NO completion:NULL];
If anyone can help me to see what I am doing wrong that would be great.
You can not present home view controller from self because it is already dismissed. You should change
[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:home animated:NO completion:NULL];
to
UIViewController *parentViewController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^
{
[parentViewController presentViewController:home animated:NO completion:nil];
}];
I have a screen tutorial for my app. I have a UIPageViewController setup to manage 3 View Controllers. Once you get to the last view on the tutorial you press a "done" button and the tutorial is supposed to go away.
I can't seem to find a way to pop/dismiss the tutorial. I have tried the following:
[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popViewControllerAnimated:YES];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
Any ideas would be appreciated.
The View Controllers being managed are subviews of UIViewController if that's of any help.
EDIT
This is how I set up the views:
In my UIPageViewController I have the following:
-(void)viewDidLoad{
[self.pageController setViewControllers:#[tutorialPages[0]]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
}
- (void)setupContentViews{
ScreenTutorial_1ViewController *screenTutorial1 = [[ScreenTutorial_1ViewController alloc] initWithNibName:#"ScreenTutorial_1ViewController" bundle:nil];
ScreenTutorial_2ViewController *screenTutorial2 = [[ScreenTutorial_2ViewController alloc] initWithNibName:#"ScreenTutorial_2ViewController" bundle:nil];
ScreenTutorial_3ViewController *screenTutorial3 = [[ScreenTutorial_3ViewController alloc] initWithNibName:#"ScreenTutorial_3ViewController" bundle:nil];
tutorialPages = #[screenTutorial1, screenTutorial2, screenTutorial3];
NSLog(#"tutorPages = %#", tutorialPages);
}
First, I strongly recommend you using:
[[NSUserDefaults standardUserDefaults] setObject:#YES forKey:#"hasSeenTutorial"];
Secondly, how are you presenting your PageViewController? In order to dismiss it like you have, you need to use (from a UIViewController):
[self presentViewController:tutorial animated:YES completion:nil];
Where tutorial is your Tutorial View controller. This will slide it up across the screen (or you can not animate it), and then you can dismiss it like you have.
Wild shot in the dark here, but I think you could reach your UIPageVieWController by calling self.parentViewController in your child controllers.
You could then either dismiss it (if it's modally presented) or pop it.
I just realized that I had 2 views in a xib file and the IBAction was connected to the wrong one. I've been copying and pasting buttons, labels...etc. On one of those pastes, I must have copied the pasted the entire view. I deleted it and used the following command which did dismiss the View:
[self dismissViewControllerAnimated:YES completion:nil];
I am using the facebook FBFriendPickerViewController and want the user to only be able to select one friend and then have it dismiss the view controller. In the FBFriendPickerDelegate, under the selectionDidChange method I am trying to capture what friend they selected and then dismiss the view controller. I can't get it to dismiss, I feel like I have done this type of thing many times before so I feel kind of dumb asking this, but I feel like I have exhausted every variation of this and nothing works.
-(void)friendPickerViewControllerSelectionDidChange:(FBFriendPickerViewController *)friendPicker{
self.selectedFriends = friendPicker.selection;
NSLog(#"%#", self.selectedFriends);
[friendPicker dismissViewControllerAnimated:YES completion:nil];
}
I have also tried
[[friendPicker parentViewController] dismissViewControllerAnimated:YES completion:nil];
[self.friendPickerController dismissViewControllerAnimated:YES completion:nil];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
[[friendPicker navigationController] dismissViewControllerAnimated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
all to no avail.
Since it's a navigation Viewcontroller that you likely pushed, you would want to pop it:
[self.navigationController popViewControllerAnimated:YES];
If you present the friendpicker controller modally you can dismiss it by using the facebookViewControllerCancelWasPressed and the facebookViewControllerDoneWasPressed methods of the FBViewControllerDelegate protocol. If you conform to FBFriendPickerDelegate you automatically conform to the first one.