I have a navigation controller that starts my app (rootViewController is the navigationController). Then inside one of the views of the navigation I call:
TabBarController *tab = [[TabBarController alloc] init];
// Presentation
[self presentViewController:tab animated:NO completion:nil];
Then one of the tabs calls the UIImagePickerController and then saves the image on another thread. Then I return to the main queue and run:
dispatch_async(dispatch_get_main_queue(), ^{
[picker dismissViewControllerAnimated:YES completion:nil];
PostViewController *post = [[PostViewController alloc] init];
// Presentation
[self presentViewController:post animated:NO completion:nil];
});
But the post view never gets called and the viewDidLoad never gets hit in the PostViewController.m. Instead the imagePicker disappears and returns to the tabBarController. How do I fix this?
Assuming that you PostViewController object is not nil , Present the view controller after the dismiss process of picker ViewController is completed . Try this Code
dispatch_async(dispatch_get_main_queue(), ^{
[picker dismissViewControllerAnimated:YES completion:^{
PostViewController *post = [[PostViewController alloc] init];
// Presentation
[self presentViewController:post animated:NO completion:nil];
}];
});
Related
This is my viewController.m file
- (IBAction)defaultAction:(id)sender {
SimpleViewController *simpleView = [[SimpleViewController alloc]init];
[self presentViewController:simpleView animated:YES completion:nil];
}
- (IBAction)flipAction:(id)sender {
SimpleViewController *simpleView = [[SimpleViewController alloc]init];
[simpleView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:simpleView animated:YES completion:nil];
}
- (IBAction)dissolveAction:(id)sender {
SimpleViewController *simpleView = [[SimpleViewController alloc]init];
[simpleView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:simpleView animated:YES completion:nil];
}
- (IBAction)pageCurlAction:(id)sender {
SimpleViewController *simpleView = [[SimpleViewController alloc]init];
[simpleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentViewController:simpleView animated:YES completion:nil];
}
I have another class SimpleViewController.There is a button action like this in this class.
- (IBAction)dismissMeAction:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
My default, flip and dissolve button works well but when i click pageCurl my apps crashes. What is the reason behind this?
The UIModalTransitionStylePartialCurl is a style that requires additional special configuration. Here is from Apple's doc:
Declaration
UIModalTransitionStylePartialCurl
Discussion
When the view controller is presented, one corner of the current view
curls up to reveal the presented view underneath. On dismissal, the
curled up page unfurls itself back on top of the presented view. A
view controller presented using this transition is itself prevented
from presenting any additional view controllers. This transition style
is supported only if the parent view controller is presenting a
full-screen view and you use the UIModalPresentationFullScreen modal
presentation style. Attempting to use a different form factor for the
parent view or a different presentation style triggers an exception.
so you have to make sure your self view is a full-screen and add full-screen presentation style to simpleView as below
- (IBAction)pageCurlAction:(id)sender {
SimpleViewController *simpleView = [[SimpleViewController alloc]init];
[simpleView setModalPresentationStyle:UIModalPresentationFullScreen];
[simpleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentViewController:simpleView animated:YES completion:nil];
}
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 am trying to have it so a user can choose a photo from their album into an imageview. It seems to work fine if I'm using a push segue to that viewcontroller that has the button to perform the action, but when I change it to modal segue, nothing happens when I click the button to run the function. What is the cause of this exactly?
Method:
- (IBAction)choosePhotoFromAlbum:(id)sender {
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self.navigationController presentViewController:imgPicker animated:YES completion:nil];
}
You're trying to present it from the navigation controller, but your view controller is modal. Change
[self.navigationController presentViewController:imgPicker animated:YES completion:nil];
to
[self presentViewController:imgPicker animated:YES completion:nil];.
you're trying to present it from the navigation controller, but your view controller is modal. so just write
[self presentViewController:YourImagePickerController animated:YES completion:nil];.
This worked in iOS6, so not sure what the issue is.
inside my UINavigationController (ioNavController) I present the UIImagePickerController with the Following:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.modalInPopover = YES;
imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:imagePicker animated:NO completion:^{ }];
in my UIImagePickerControllerDelegate (which does get called)I have the Following:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
//This does not work
[ioNavController dismissViewControllerAnimated:YES completion:^{ /* Cleanup if Needed */ }];
//This does not work
[[picker parentViewController] dismissViewControllerAnimated:YES completion:^{ /* Cleanup if Needed */ }];
//This does not work
[picker removeFromParentViewController];
// This presents a new view on the Nav Controller. It shows the new view ontop of the ImagePicker. Image Picker View does not repond to touches.
[ioNavController pageToSelect:0];
}
Your delegate it's in the same controller that called the imagepicker? The same controller that called presentViewController should call the line below, and the imagepicker will be removed correctly.
[self dismissViewControllerAnimated:YES completion:nil]; //self here it's the same reference that called presentViewController
let me know if worked or helped.
The UIImagePickerController will remove itself when you use this code:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)pPicker {
[pPicker dismissViewControllerAnimated:YES completition:NULL]; }
This only accours if you are presenting in a view controller that is managed by a navigation controller.
The reproduction steps are:
1 - Present a view controller using UIModalPresentationCurrentContext
self.definesPresentationContext = YES;
ViewController* viewController = [[ViewController alloc] init];
viewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentOnViewController presentViewController:viewController animated:YES completion:nil];
2 - Present a view controller over the top using the default full screen presentation style
ViewController* viewController = [[ViewController alloc] init];
[self presentViewController:viewController animated:YES completion:nil];
3 - Dismiss the top presented view controller (the full screen one)
[self dismissViewControllerAnimated:YES completion:nil];
Now the problem is the 2nd view controller (presented using UIModalPresentationCurrentContext) disappears. Also it is impossible to present another view controller using UIModalPresentationCurrentContext, because the system thinks its still there.
I believe the issue is a bug in the framework. As mentioned it only occurs when the presenting in a view controller managed by a navigation controller. There is a nasty work around which uses the containment API. It creates a dummy view controller which views are presented from. The steps are:
1 - When presenting a view in context who's parent is a navigation controller, use a dummy view controller:
- (void)presentInContext
{
UIViewController* presentOnViewController = self;
if ([self.parentViewController isKindOfClass:[UINavigationController class]])
{
// Work around - Create an invisible view controller
presentOnViewController = [[DummyViewController alloc] init];
presentOnViewController.view.frame = self.view.frame;
// Containment API
[self addChildViewController:presentOnViewController];
[self.view addSubview:presentOnViewController.view];
[presentOnViewController didMoveToParentViewController:self];
presentOnViewController.definesPresentationContext = YES;
}
ViewController* viewController = [[ViewController alloc] init];
viewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentOnViewController presentViewController:viewController animated:YES completion:nil];
}
2 - When dismissing the view controller tidy up
- (void)dismissSelf
{
__weak UIViewController* presentingViewController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^{
// Remove the dummy view controller
if ([presentingViewController isKindOfClass:[DummyViewController class]])
{
[presentingViewController willMoveToParentViewController:nil];
[presentingViewController.view removeFromSuperview];
[presentingViewController removeFromParentViewController];
}
}];
}
Thats it... The fix is dirty, but does the trick with no visual flicker.