I have a viewController VC1 where I present an UIImagePickerController with sourcetype camera.. then after taking a picture, transition to a new viewController where the image is used. The problem is, how can I dismiss the imagePicker AND seamlessly transition to my new viewController. For example in my
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
method, I attempt to use either of the two methods to dismiss the picker and present the new viewController seamlessly
[self.presentedViewController presentViewController:postControl animated:NO completion:^{
[picker dismissViewControllerAnimated:NO completion:nil];
}];
/*
[picker dismissViewControllerAnimated:NO completion:^{
[self presentViewController:postControl animated:NO completion:nil];
}];
*/
Obviously the first one is wrong because I am asking the presenting view controller to dismiss itself during its animation, resulting in an error. If I change picker to self.presentingViewController it never dismisses the camera and the second bit of code(the one commented) works, but not seamlessly, In other words, You can SEE the transition.
Sorry for not understanding this problem but I am just not seeing it. How can I dismiss the camera AFTER or BEFORE presenting postControl seamlessly?
As in, you cannot see the transition?
UIViewController* toPresentViewController = [[UIViewController alloc] init];
[picker dismissViewControllerAnimated:YES completion:^
{
[self.presentingViewController presentViewController:toPresentViewController animated:YES completion:nil]
}];
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];
}];
While trying to present the contact editor VC I get an error message of
Warning: Attempt to present <UINavigationController: 0x15fe273f0> on <UINavigationController: 0x15fe0e730> while a presentation is in progress!
I believe this is because my UIImagePickerController is still active.
Here is my didFinish method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerOriginalImage];
animated:YES];
[picker dismissViewControllerAnimated:YES completion:NULL];
[self scanWithImage:image];
}
As you can see the second message should dismiss the VC but it does not, and it stays up until the end of the execution of the application.
scanWithImage: eventually calls showNewPersonViewController here is that method:
-(void)showNewPersonViewController
{
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
picker.displayedPerson = _person;
picker.newPersonViewDelegate = self;
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];
// Change status bar back to black due to white contact creation.
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
[self presentViewController:navigation animated:YES completion:nil];
}
On the last line in that method I get the error message, then the app finishes its execution and returns to the main VC.
How can I avoid this and properly display the contact creation VC?
Let's try:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerOriginalImage];
// I think picker should change to self == this class dismisses, not picker dismisses
[self dismissViewControllerAnimated:YES completion:nil];
}
// should implement [self scanWithImage:image]; in parent class which contains VC has pickerView.
// Because after dismissing, VC which contains picker is dealloc, how can you call [self presentViewController:navigation animated:YES completion:nil];
I think this can help you
I think you are presenting two VCs at same time with animation.
Set one of VC's animation to NO while presenting or dismissing and see if the warning goes away.
I'm not 100% sure but if you want both animations you should run the second one on the first one's completion block or use a timer to delay the second view controller's navigation start.
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]; }
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.
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.